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

int main() {
	int t, n, w1, w2, h1, h2, w1m, w2m, h1m, h2m;
	scanf("%d", &t);
	for (int i=0; i<t; i++) {
		scanf("%d", &n);
		scanf("%d%d%d%d", &w1m, &w2m, &h1m, &h2m);
		bool ok = true;
		for (int j=1; j<n; j++) {
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			if (w1<=w1m && w2>=w2m && h1<=h1m && h2>=h2m) {
				w1m = w1;
				w2m = w2;
				h1m = h1;
				h2m = h2;
				ok = true;
			}
			else if (!(w1>=w1m && w2<=w2m && h1>=h1m && h2<=h2m)) {
				//printf("(%d %d) m=(%d %d) (%d %d) m=(%d %d)\n", w1, w2, w1m, w2m, h1, h2, h1m, h2m);
				ok = false;
				if (w1 < w1m) w1m=w1;
				if (w2 > w2m) w2m=w2;
				if (h1 < h1m) h1m=h1;
				if (h2 < h2m) h2m=h2;
			}
		}
		printf("%s\n", ok ? "TAK" : "NIE");
	}
	return 0;
}