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
#include <cstdio>
#define INF 2123456789

int t, n, w1, w2, h1, h2;
int minw, maxw, minh, maxh;
bool odp;

int main () {
	scanf("%d",&t);
	while(t--) {
		minw = INF; minh = INF;
		maxw = 0; maxh = 0;
		odp = false;
		scanf("%d",&n);
		for(int i = 0; i < n; ++i) {
			scanf("%d%d%d%d",&w1,&w2,&h1,&h2);
			if(w1 < minw) {
				minw = w1;
				odp = false;
			}
			if(w2 > maxw) {
				maxw = w2;
				odp = false;
			}
			if(h1 < minh) {
				minh = h1;
				odp = false;
			}
			if(h2 > maxh) {
				maxh = h2;
				odp = false;
			}
			
			if(minw == w1 && maxw == w2 && minh == h1 && maxh == h2) odp = true;
		}
	printf("%s\n", odp ? "TAK" : "NIE");
	}
return 0;
}