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

using namespace std;

void solve();

struct Company {
	int minX;
	int minY;
	int maxX;
	int maxY;

	bool isAtLeastAsGoodAs(Company other) {
		return minX <= other.minX
			&& minY <= other.minY
			&& maxX >= other.maxX
			&& maxY >= other.maxY;
	}
};

int main() {
	ios_base::sync_with_stdio(0);
	int test_cases = 0;
	cin >> test_cases;
	for(int i = 1; i <= test_cases; ++i)
		solve();
	return 0;
}

inline Company getCompany() {
	Company newCompany;
	cin >> newCompany.minX;
	cin >> newCompany.maxX;
	cin >> newCompany.minY;
	cin >> newCompany.maxY;
	return newCompany;
}

inline vector<Company> loadData() {
	int companyCount = 0;
	cin >> companyCount;
	vector<Company> companies(companyCount);
	for(int i = 0; i < companyCount; ++i) {
		companies[i] = getCompany();
	}
	return companies;
}

inline Company findBestCandidate(vector<Company> companies) {
	Company bestCandidate = companies[0];
	for(Company otherCandidate : companies) {
		if(otherCandidate.isAtLeastAsGoodAs(bestCandidate))
			bestCandidate = otherCandidate;
	}
	return bestCandidate;
} 

inline bool isBest(Company candidate, vector<Company> companies) {
	bool trueSoFar = true;
	for(Company otherCandidate : companies) {
		if(! candidate.isAtLeastAsGoodAs(otherCandidate))
			trueSoFar = false;
	}
	return trueSoFar;
}

inline void solve() {
	vector<Company> companies = loadData();
	Company bestCandidate = findBestCandidate(companies);
	if(isBest(bestCandidate, companies))
		cout << "TAK\n";
	else
		cout << "NIE\n";
}