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

using namespace std;

struct Mirror {
	int w1;
	int w2;
	int h1;
	int h2;
	Mirror(int w1, int w2, int h1, int h2): w1(w1), w2(w2), h1(h1), h2(h2) { }
};

bool solve(const vector<Mirror>& mirrors){
	auto& mirror = mirrors.front();
	int best_w1 = mirror.w1;
	int best_w2 = mirror.w2;
	int best_h1 = mirror.h1;
	int best_h2 = mirror.h2;
	bool best = true;
	for(Mirror m: mirrors){
		if(m.w1<best_w1){
			best_w1 = m.w1;
			best = false;
		}
		if(m.w2>best_w2){
			best_w2 = m.w2;
			best = false;
		}
		if(m.h1<best_h1){
			best_h1 = m.h1;
			best = false;
		}
		if(m.h2>best_h2){
			best_h2 = m.h2;
			best = false;
		}
		if(m.w1 == best_w1 && m.w2 == best_w2 && m.h1 == best_h1 && m.h2 == best_h2)
			best = true;
	}
	return best;
}

int main(){

	int tests;
	scanf("%d", &tests);

	while(tests--){
		int factories, w1, w2, h1, h2;
		vector<Mirror> mirrors;
		scanf("%d", &factories);
		while(factories--){
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			mirrors.push_back(Mirror(w1, w2, h1, h2));
		}
		printf("%s\n", (solve(mirrors) ? "TAK" : "NIE"));
	}

	return 0;
}