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>
using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		
		int min_w1 = 1e9 + 1;
		int max_w2 = -1;
		int min_h1 = 1e9 + 1;
		int max_h2 = -1;
		
		bool possible = true;
		while (n--) {
			int w1, w2,h1,h2;
			cin >> w1 >> w2 >> h1 >> h2;
			
			bool changed = false;
			if (w1 < min_w1) {min_w1 = w1; changed = true;}
			if (h1 < min_h1) {min_h1 = h1; changed = true;}
			if (w2 > max_w2) {max_w2 = w2; changed = true;}
			if (h2 > max_h2) {max_h2 = h2; changed = true;}
			
			if (changed)
				possible = false;
			if (w1 == min_w1 && w2 == max_w2 && h1 == min_h1 && h2 == max_h2)
				possible = true;
		}
		
		cout << (possible ? "TAK" : "NIE") << endl;
	}
	return 0;
}