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

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	int t, n;
	cin >> t;
	int w1, w2, h1, h2;
	int bestw1, bestw2, besth1, besth2;
	int minw1 = INT_MAX;
	int maxw2 = 0;
	int minh1 = INT_MAX;
	int maxh2 = 0;
	bool found;
	while(t--){
		cin >> n;
		minw1 = INT_MAX;
		maxw2 = 0;
		minh1 = INT_MAX;
		maxh2 = 0;
		found = false;
		while(n--){
			cin >> w1;
			cin >> w2;
			cin >> h1;
			cin >> h2;
			minw1 = minw1 < w1 ? minw1 : w1;
			maxw2 = maxw2 > w2 ? maxw2 : w2;
			minh1 = minh1 < h1 ? minh1 : h1;
			maxh2 = maxh2 > h2 ? maxh2 : h2;

			if(w1 == minw1 && w2 == maxw2 && minh1 == h1 && maxh2 == h2){
				bestw1 = w1;
				bestw2 = w2;
				besth1 = h1;
				besth2 = h2;
			}
			if(bestw1 == minw1 && bestw2 == maxw2 && minh1 == besth1 && maxh2 == besth2){
				found = true;
			}
			else
				found = false;
		}
		//cout << minw1 << " " << maxw2 << " " << minh1 << " " << maxh2 << endl;
		cout << (found ? "TAK" : "NIE") << endl;
	}
}