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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

struct miracle{
	int minW;
	int maxW;
	int minH;
	int maxH;
};

bool byMaxW(miracle const &a, miracle const &b){ 
        return a.minW < b.minW;
}

int main(){
	int n = 0, t = 0;
	int minMajorW = 0, maxMajorW = 0, minMajorH = 0, maxMajorH = 0;
	int majority = 0;  
	
	cin >> t;
	
	bool tabAns[t];
	for(int k = 0 ; k < t ; k++){
		tabAns[k] = false;
	}
	

	
	for(int i = 0 ; i < t ; i++){
		cin >> n;
		miracle tab[n];
		for(int j = 0 ; j < n ; j++){
			cin >> tab[j].minW >> tab[j].maxW >> tab[j].minH >> tab[j].maxH;
			/*
			if(minW < minMajorW){
				minMajorW = minW;
				majority++;
			}
			if(maxW > maxMajorW){
				maxMajorW = maxW;
				majority++;
			}
			if(minH < minMajorH){
				minMajorH = minH;
				majority++;
			}
			if(maxH > maxMajorH){ 
				maxMajorH = maxH;
				majority++;
			}
			if(majority == 4){
				tab[i] = true;
			}else if(majority > 0 && majority < 4){
				tab[i] = false;
			}
			majority = 0;
			*/
		}
		sort(tab, tab+n, byMaxW);
	for(int q = 0 ; q < n ; q++){
	}
		for(int j = 1 ; j < n ; j++){
			if(tab[j].minW >= tab[0].minW &&
				tab[j].minH >= tab[0].minH &&
				tab[j].maxH <= tab[0].maxH &&
				tab[j].maxH <= tab[0].maxH){
				tabAns[i] = true;
			}else{
				tabAns[i] = false;
				break;
			}
		}
	}
	
	for(int i = 0 ; i < t ; i++){
		if(tabAns[i]){
			cout << "TAK" << endl;
		}else{
			cout << "NIE" << endl;
		}
	}
	
	
	return 0;
}