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
#include <algorithm>
#include <iostream>
using namespace std;

const int inf = 1e9+10;

int main() {
	ios_base::sync_with_stdio(false);

	int t; cin >> t;

	while(t--) {
		int n; cin >> n;

		int winner = -1;
		int minW = inf, maxW = 0, minH = inf, maxH = 0;

		for (int i = 0; i < n; i++) {
			int w1, w2, h1, h2; cin >> w1 >> w2 >> h1 >> h2;

			if (w1 < minW) {
				winner = -1;
				minW = w1;
			}
			if (w2 > maxW) {
				winner = -1;
				maxW = w2;
			}

			if (h1 < minH) {
				winner = -1;
				minH = h1;
			}
			if (h2 > maxH) {
				winner = -1;
				maxH = h2;
			}

			// cerr << minW << ' ' << maxW << ' ' << minH << ' ' << maxH << '\n';

			if ((winner == -1) && (w1 == minW) && (w2 == maxW) && (h1 == minH) && (h2 == maxH)) {
				winner = i;
			}
		}

		cout << ((winner != -1) ? "TAK" : "NIE") << '\n';
	}

	return 0;
}