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

int main(void){
	long numTests, numSets, x1, x2, y1, y2, minX, maxX, minY, maxY;
	bool ok;
	
	scanf("%ld",&numTests);
	
	for(int t=0;t<numTests;++t){
		scanf("%ld",&numSets);
		scanf("%ld %ld %ld %ld",&minX,&maxX,&minY,&maxY);
		ok = true;
		
		for(int s=1;s<numSets;++s){
			scanf("%ld %ld %ld %ld",&x1,&x2,&y1,&y2);
			
			if(x1<=minX && x2>=maxX && y1<=minY && y2>=maxY){
				minX = x1;
				maxX = x2;
				minY = y1;
				maxY = y2;
				ok = true;
				continue;
			}
			
			if(x1<minX){
				minX = x1;
				ok = false;
			}
			
			if(x2>maxX){
				maxX = x2;
				ok = false;
			}
			
			if(y1<minY){
				minY = y1;
				ok = false;
			}
			
			if(y2>maxY){
				maxY = y2;
				ok = false;
			}
		}
		
		if(ok)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
	
	return 0;
}