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


typedef struct {
	unsigned int minW, maxW;
	unsigned int minH, maxH;

}dimensions;

bool isMajor(dimensions d1, dimensions d2){
	return(	(d1.minW <= d2.minW) &&
		(d1.maxW >= d2.minW) &&
		(d1.minH <= d2.minH) &&
		(d1.maxH >= d2.maxH) )? true : false;
}

bool isEqual(dimensions d1, dimensions d2){
	return(	(d1.minW == d2.minW) &&
		(d1.maxW == d2.minW) &&
		(d1.minH == d2.minH) &&
		(d1.maxH == d2.maxH) )? true : false;
}


using namespace std;

int main(void){
	unsigned int t;

	scanf("%u", &t);

	while(t--){ //Główna pętla kolejne testy
		unsigned int n;
		bool isThatMajor = false;
		dimensions dim;
		vector<dimensions> major;
		scanf("%u", &n);
		while(n--){//Wczytanie kolejnych wyników
			scanf("%u", &dim.minW);
			scanf("%u", &dim.maxW);
			scanf("%u", &dim.minH);
			scanf("%u", &dim.maxH);

			if(major.size()){
				vector<dimensions>::iterator it = major.begin();
				vector<dimensions>::iterator end = major.end();

				for(; it != end; it++){
					if(isMajor(dim, *it)){
						it = major.erase(it);
						isThatMajor = true;
					}else if(!isMajor(*it, dim)){
						isThatMajor = true;		
					}
					
				}
			}else{
				isThatMajor = true;
			}

			if(isThatMajor){
				major.push_back(dim);
				isThatMajor = false;
			}
		}
		
		if(major.size() == 1){
			printf("TAK\n");
		}else{
			printf("NIE\n");
		}

		major.empty();

	}


return 0;
}