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
48
#include <algorithm>
#include <iostream>
#define INFTY 1000000
using namespace std;

struct Size
{
	int w,W,h,H;
};

bool maj(Size a, Size b)
{
	return a.w<=b.w && a.W>=b.W
	&& a.h<=b.h && a.H>=b.H;
}

int t;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> t;

	for (int i=0;i<t;++i) {
		int n;
		Size smax = {INFTY,-INFTY,INFTY,-INFTY};
		Size smaj = smax;
		bool major=false;
		cin >> n;

		for (int i=0;i<n;++i) {
			Size s;
			cin >>s.w >>s.W >>s.h >>s.H;
			smax.w = min(smax.w, s.w);
			smax.h = min(smax.h, s.h);
			smax.W = max(smax.W, s.W);
			smax.H = max(smax.H, s.H);
			if (!maj(smaj,smax) && maj(s,smax))
				smaj = s;
		}

		cout << (maj(smaj,smax)? "TAK\n" : "NIE\n");
	}

	return 0;
}