1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <algorithm>
using namespace std;
//#define dump(...) cerr << #__VA_ARGS__ << " = " << (__VA_ARGS__) << endl
#define dump(...)

struct Record
{
	unsigned wmin;
	unsigned wmax;
	unsigned hmin;
	unsigned hmax;
	Record(){}
	Record(unsigned wmin, unsigned wmax, unsigned hmin, unsigned hmax): wmin(wmin), wmax(wmax), hmin(hmin), hmax(hmax) {}
	bool operator==(Record const & other) const { return this->wmin == other.wmin && this->wmax == other.wmax && this->hmin == other.hmin && this->hmax == other.hmax; }
	Record operator+(Record const & other) const { return Record(min(this->wmin, other.wmin), max(this->wmax, other.wmax), min(this->hmin, other.hmin), max(this->hmax, other.hmax)); }
};

ostream & operator<<(ostream & os, Record const & other) { return os << other.wmin << " " << other.wmax << " " << other.hmin << " " << other.hmax; }
istream & operator>>(istream & is, Record & other) { return is >> other.wmin >> other.wmax >> other.hmin >> other.hmax; }

int main()
{
	unsigned t, n;
	cin >> t;
	while (t--)
	{
		bool maj = true;
		Record all(1234567890, 0, 1234567890, 0);
		cin >> n;
		while (n--)
		{
			Record cur;
			cin >> cur;
dump(cur);
			Record const tmp = all + cur;
dump(tmp);
			maj &= all == tmp;
			maj |= cur == tmp;
dump(maj);
			all = tmp;
dump(all);
		}
		cout << (maj?"TAK\n":"NIE\n");
//		cerr << all << endl;
	}
}