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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 100009;
struct mirror
{
	int minW, maxW;
	int minH, maxH;

	mirror() {};
	mirror(int a, int b, int c, int d)
		{ minW = a; maxW = b; minH = c; maxH = d; }
};

int t, n;
mirror last, thisOne;
bool ok;

mirror add(mirror x, mirror y)
{
	ok = 1;
	if(x.minW > y.minW)
	{
		ok = 0;
		x.minW = y.minW;
	}
	if(x.maxW < y.maxW)
	{
		ok = 0;
		x.maxW = y.maxW;
	}
	if(x.minH > y.minH)
	{
		ok = 0;
		x.minH = y.minH;
	}
	if(x.maxH < y.maxH)
	{
		ok = 0;
		x.maxH = y.maxH;
	}
	return x;
}

int main()
{
	bool result = 0;
	scanf("%d", &t);
	for(int j = 0; j < t; j++)
	{
		scanf("%d", &n);
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		last = mirror(a, b, c, d);
		scanf("%d%d%d%d", &a, &b, &c, &d);
		thisOne = mirror(a, b, c, d);

		mirror temp = add(thisOne, last);
		if(ok == 0)
		{
			add(last, thisOne);
			result = ok;
		} else result = 1;
		last = temp;

		for(int i = 2; i < n; i++)
		{
			scanf("%d%d%d%d", &a, &b, &c, &d);
			thisOne = mirror(a, b, c, d);
			if(result == 1)
			{
				add(last, thisOne);
				if(ok == 0)
				{
					add(thisOne, last);
					result = ok;
				}
			} else
			{
                add(thisOne, last);
                result = ok;
			}
			last = add(thisOne, last);
		}

		if(result == 1) printf("TAK\n");
			else printf("NIE\n");
	}
	return 0;
}