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

int main() {
	std::cin.sync_with_stdio(false);

	int t, n;
	std::cin >> t;

	int w1, w2, h1, h2;
	int wmin, wmax;
	int hmin, hmax;
	
	bool check = false;
	bool change = true;


	for (int i = 0; i < t; ++i) {
		std::cin >> n;

		std::cin >> wmin >> wmax >> hmin >> hmax;

		check = true;

		for (int j = 1; j < n; ++j) {
			std::cin >> w1 >> w2 >> h1 >> h2;

			if (w1 < wmin) {
				wmin = w1;
				change = true;
			}
			if (w2 > wmax) {
				wmax = w2;
				change = true;
			}
			if (h1 < hmin) {
				hmin = h1;
				change = true;
			}
			if (h2 > hmax) {
				hmax = h2;
				change = true;
			}

			if (wmin == w1 && wmax == w2 && hmin == h1 && hmax == h2)
				check = true;

			if (change) {
				change = false;
				if (wmin != w1 || wmax != w2 || hmin != h1 || hmax != h2)
					check = false;
			}
		}
		
		if (check) std::cout << "TAK\n";
		else std::cout << "NIE\n";
	}

	return 0;
}