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
#include <cstdio>

#define MAX_INPUT 1000000000 
//#define debug(x...) printf(x) 
#define debug(x...)  

int main()
{
	int t = 0;
	scanf("%d", &t);
	while (t--)
	{
		int n = 0;
		scanf("%d", &n);
		int w1_min = MAX_INPUT;
		int w2_max = 0;
		int h1_min = MAX_INPUT;
		int h2_max = 0;
		bool majorFound = false;
		for (int i = 0; i < n; ++i)
		{
			int w1, w2, h1, h2;
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			debug("w1 = %d; w2 = %d; h1 = %d; h2 = %d\n", w1, w2, h1, h2);
			if (w1 <= w1_min && w2 >= w2_max && h1 <= h1_min && h2 >= h2_max)
			{
				majorFound = true;
			}
			else if (w1 < w1_min || w2 > w2_max || h1 < h1_min || h2 > h2_max)
			{
				majorFound = false;
			}
			debug("majorFound = %s\n", majorFound?"true":"false");
			if (w1 < w1_min)
				w1_min = w1;
			if (w2 > w2_max)
				w2_max = w2;
			if (h1 < h1_min)
				h1_min = h1;
			if (h2 > h2_max)
				h2_max = h2;
			debug("w1_min = %d; w2_max = %d; h1_min = %d; h2_max = %d\n", w1_min, w2_max, h1_min, h2_max);
		}
		if (majorFound)
		{
			printf("TAK\n");
		}
		else
		{
			printf("NIE\n");
		}
	}
	return 0;
}