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

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, n;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		scanf("%d", &n);
		int a, b, c, d;
		int ba, bb, bc, bd;
		bool found = true;
		scanf("%d%d%d%d", &ba, &bb, &bc, &bd);
		for (int j = 1; j < n; j++) {
			scanf("%d%d%d%d", &a, &b, &c, &d);
			if (a <= ba && b >= bb && c <= bc && d >= bd) {
				ba = a;
				bb = b;
				bc = c;
				bd = d;
				found = true;
			} else if (a >= ba && b <= bb && c >= bc && d <= bd) {
				//
			} else {
				found = false;
				ba = min(a, ba);
				bb = max(b, bb);
				bc = min(c, bc);
				bd = max(d, bd);
			}
		}
		if (found)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
	return 0;
}