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

//is w1 h1 in w2 h2?
bool contains(int w1, int h1, int w2, int h2)
{
	return (w1 <= w2) && (h1 <= h2);
}


int min(int A, int B)
{
	if(A < B) return A;
	return B;
}

int max(int A, int B)
{
	if(A > B) return A;
	return B;
}
int main()
{
	int t;
	int n;
	int w1, w2, h1, h2;
	int wmin, wmax, hmax, hmin;
	scanf("%d", &t);
	while(t--)
	{

		bool majoranta = true;
		scanf("%d", &n);
		n -= 1;
		scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
		wmin = w1;
		wmax = w2;
		hmin = h1;
		hmax = h2;
		while(n--)
		{

			//printf("Aktualna majoranta %d %d %d %d\n", wmin, wmax, hmin, hmax);
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			//if w1h1 is in wmin hmin and wmax hmax is in w2h2 -> mamy nowa majorante
			if(contains(w1, h1, wmin, hmin) && contains(wmax, hmax, w2, h2))
			{
				majoranta = true;
				wmin = w1;
				wmax = w2;
				hmin = h1;
				hmax = h2;
			}
			else if(w1 < wmin || w2 > wmax || h1 < hmin || h2 > hmax)
			{
				majoranta = false;
				wmin = min(w1, wmin);
				wmax = max(w2, wmax);
				hmin = min(h1, hmin);
				hmax = max(h2, hmax);
			}
		}

		if(majoranta) printf("TAK\n");
		else printf("NIE\n");
	}
	

	return 0;
}