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
55
56
57
58
59
60
61
62
#include <stdio.h>

main(){
	int t,n, i,j,a,b,c,d,a1,b1,c1,d1,w1,w2;
	bool ok = false;
	scanf("%d",&t);
	for(i=0;i<t;i++){
		ok = true;
		scanf("%d",&n);
		scanf("%d %d %d %d",&a,&b,&c,&d);
		for(j = 1; j < n;j++){
		    scanf("%d %d %d %d",&a1,&b1,&c1,&d1);
		    if((a1==a) && (b1==b)){
			w1 = 0;
		    } else if((a1 >= a) && (b1 <= b)){
			w1 = 1;
		    } else if((a1 <= a) && (b1 >= b)){
			w1 = 2;
		    } else {
			w1 = -1;
		    }
		    
		    if((c1==c) && (d1==d)){
			w2 = 0;
		    } else if((c1 >= c) && (d1 <= d)){
			w2 = 1;
		    } else if((c1 <= c) && (d1 >= d)){
			w2 = 2;
		    } else {
			w2 = -1;
		    }
		    
		    if(w2==-1 || w1 == -1){
			ok = false;
		    }
		    if(w2==1 && w1==2){
			ok = false;
		    }
		    if(w1==1 && w2==2){
			ok = false;
		    }
		    if((w2==0 || w2==2) && (w1==0 || w1==2)){
			ok = true;
		    }
		    if(w1 == 2){
			a = a1;
			b = b1;
		    }
		    if(w2 == 2){
			c = c1;
			d = d1;
		    }
		    
		}
		if(ok){
		    printf("TAK\n");
		} else {
		    printf("NIE\n");
		}
	}
	return 0;
}