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
#include<iostream>
#include<algorithm>

using namespace std;

bool doesCommonExist(int n) {
	int optW1, optW2, optH1, optH2;
	cin >> optW1 >> optW2 >> optH1 >> optH2;
	int minW1 = optW1, maxW2 = optW2, minH1 = optH1, maxH2 = optH2;

	int w1, w2, h1, h2;
	for(int i = 1; i < n; i++) {
		cin >> w1 >> w2 >> h1 >> h2;
		minW1 = min(w1, minW1);
		maxW2 = max(w2, maxW2);
		minH1 = min(h1, minH1);
		maxH2 = max(h2, maxH2);

		if(w1 == minW1 && w2 == maxW2 && 
				h1 == minH1 && h2 == maxH2) {
			optW1 = w1; optW2 = w2;
			optH1 = h1; optH2 = h2;
		}
	}
	return optW1 == minW1 && optW2 == maxW2 && optH1 == minH1 && optH2 == maxH2;
}

int main() {
	int T;
	cin >> T;
	for(int t = 0; t < T; t++) {
		int n;
		cin >> n;
		cout << ((doesCommonExist(n)) ? "TAK" : "NIE") << endl;
	}
}