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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int t,n,w1,w2,h1,h2;
int it;
bool major;
struct Best
{
	int minw, maxw, minh, maxh, index;
};

Best best;

int main()
{
	
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		it = 0;
		best.minw = best.minh = 1000000000;
		best.maxw = best.maxh = 0;
		best.index = 0;
		major = true;
		
		scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
		best.minw = w1;
		best.maxw = w2;
		best.minh = h1;
		best.maxh = h2;
		n--;
		it++;
		
		while(n--)
		{
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			
			if(w1 <= best.minw && w2 >= best.maxw && h1 <= best.minh && h2 >= best.maxh)
			{
				best.minw = w1;
				best.maxw = w2;
				best.minh = h1;
				best.maxh = h2;
				best.index = it;
				major = true;
			}
			else if(w1 < best.minw || w2 > best.maxw || h1 < best.minh || h2 > best.maxh)
			{
				best.minw = min(best.minw, w1);
				best.minh = min(best.minh, h1);
				best.maxw = max(best.maxw, w2);
				best.maxh = max(best.maxh, h2);
				major = false;
			}
			it++;
		}
		
		if(major)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
}