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
#include <stdio.h>
#include <algorithm>

inline bool contains(int a, int b, int x)
{
	return a <= x && x <= b;
}

inline bool contains(int a, int b, int c, int d, int aa, int bb, int cc, int dd)
{
	return contains(a, b, aa) && contains(a, b, bb) && contains(c, d, cc) && contains(c, d, dd);
}

int main()
{
	int T;
	scanf("%d\n", &T);

	while(T--)
	{
		int ile;
		scanf("%d\n", &ile);

		int a,b,c,d,A,B,C,D;
		scanf("%d %d %d %d\n", &A, &B, &C, &D);
		bool result = true;
		for(int i = 1 ; i < ile ; ++i)
		{
			scanf("%d %d %d %d\n", &a, &b, &c, &d);

			if(contains( a, b, c, d, A, B, C, D))
			{
				result = true;
				A = std::min(a, A);
				B = std::max(b, B);
				C = std::min(c, C);
				D = std::max(d, D);
			}
			else if(!contains(A, B, C, D, a, b, c, d))
			{
				result = false;
				A = std::min(a, A);
				B = std::max(b, B);
				C = std::min(c, C);
				D = std::max(d, D);
			}
		}
		
		if(result)
		{
			printf("TAK\n");
		}
		else
		{
			printf("NIE\n");
		}

	}
	return 0;
}