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
#include<cstdio>
#include<algorithm>
int main() {
	int t; scanf("%d", &t);
	for(int i = 0; i < t; ++i) {
		int n; scanf("%d", &n);
		int a = 0, b = 0, c = 0, d = 0;
		bool ok = true;
		for(int j = 0; j < n; ++j) {
			int w, ww, h, hh; scanf("%d %d %d %d", &w, &ww, &h, &hh);
			if (a == 0) {
				a = w; b = ww; c = h; d = hh;
				ok = true;
				continue;
			}
			else {
				if (ok) {
					if (a <= w && ww <= b && c <= h && hh <= d) {
							continue;
					}
					else {
						ok = false;
					}
				}
				if (!ok) {
					if (w <= a && b <= ww && h <= c && d <= hh) {
						ok = true;;
					}
				}
				if (w < a) {
					a = w;
				}
				if (b < ww) {
					b = ww;
				}
				if (h < c) {
					c = h;
				}
				if (d < hh) {
					d = hh;
				}
			}
		}
		if (ok) {
			printf("TAK\n");
		}
		else {
			printf("NIE\n");
		}
	}
}