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

#define REP(x, n) for(int x = 0; x < n; x++)
#define FORD(x, b, e) for(int x = b; x >= e; x--)

using namespace std;

const int MAX_R = 100007;
const int INF = 1000000001;
inline int min(int a, int b)
{
	return a < b ? a : b;
}
inline int max(int a, int b)
{
	return a > b ? a : b;
}
int a[MAX_R];
int a1[MAX_R];
int a2[MAX_R];
int b[MAX_R];
int b1[MAX_R];
int b2[MAX_R];
int c[MAX_R];
int c1[MAX_R];
int c2[MAX_R];
int d[MAX_R];
int d1[MAX_R];
int d2[MAX_R];

int main()
{
	int t;
	scanf("%d", &t);
	while(t--)
	{
		int n;
		scanf("%d", &n);
		int mia = INF;
		int mab = 0;
		int mic = INF;
		int mad = 0;
		a1[0] = mia;
		b1[0] = mab;
		c1[0] = mic;
		d1[0] = mad;
		REP(x, n)
		{
			scanf("%d %d %d %d", &a[x], &b[x], &c[x], &d[x]);
			mia = min(mia, a[x]);
			a1[x + 1] = mia;
			mic = min(mic, c[x]);
			c1[x + 1] = mic;
			mab = max(mab, b[x]);
			b1[x + 1] = mab;
			mad = max(mad, d[x]);
			d1[x + 1] = mad;
		}
		mia = INF;
		mab = 0;
		mic = INF;
		mad = 0;
		a2[n] = mia;
		b2[n] = mab;
		c2[n] = mic;
		d2[n] = mad;
		FORD(x, n - 1, 0)
		{
			mia = min(mia, a[x]);
			a2[x + 1] = mia;
			mic = min(mic, c[x]);
			c2[x + 1] = mic;
			mab = max(mab, b[x]);
			b2[x + 1] = mab;
			mad = max(mad, d[x]);
			d2[x + 1] = mad;
		}
		bool ok = 0;
		REP(x, n)
		{
			if (!(min(a1[x], a2[x + 2]) < a[x] || min(c1[x], c2[x + 2]) < c[x] || max(b1[x], b2[x + 2]) > b[x]  || max(d1[x], d2[x + 2]) > d[x]))
			{
				ok = 1;
				break;
			}
		}
		if (ok) puts("TAK");
		else puts("NIE");
			
		
	}
	return 0;
}