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
76
77
78
79
80
81
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

const int W_H_MAX = 1000000000;
const int N_MAX = 100000;
bool isMinW[N_MAX];
bool isMaxW[N_MAX];
bool isMinH[N_MAX];
bool isMaxH[N_MAX];

int main() {
	int t, n, w1, w2, h1, h2;
	scanf("%d\n", &t);
	for (int tId = 0; tId < t; ++tId) {
		scanf("%d\n", &n);
		vector<int> minWidth;
		vector<int> maxWidth;
		vector<int> minHeight;
		vector<int> maxHeight;
		int minH = W_H_MAX + 1;
		int maxH = 0;
		int minW = W_H_MAX + 1;
		int maxW = 0;
		for (int i = 0; i < n; ++i) {
			isMinW[i] = false;
			isMaxW[i] = false;
			isMinH[i] = false;
			isMaxH[i] = false;
			scanf("%d %d %d %d\n", &w1, &w2, &h1, &h2);
			if (w1 < minW) {
				minWidth.clear();
				minW = w1;
				minWidth.push_back(i);
			} else if (w1 == minW) {
				minWidth.push_back(i);
			}
			if (w2 > maxW) {
				maxWidth.clear();
				maxW = w2;
				maxWidth.push_back(i);
			} else if (w2 == maxW) {
				maxWidth.push_back(i);
			}

			if (h1 < minH) {
				minHeight.clear();
				minH = h1;
				minHeight.push_back(i);
			} else if (h1 == minH) {
				minHeight.push_back(i);
			}
			if (h2 > maxH) {
				maxHeight.clear();
				maxH = h2;
				maxHeight.push_back(i);
			} else if (h2 == maxH) {
				maxHeight.push_back(i);
			}
		}
		int x1 = minWidth.size();
		int x2 = maxWidth.size();
		int y1 = minHeight.size();
		int y2 = maxHeight.size();

		bool result = false;
		for (int i = 0; i < x1; ++i) isMinW[minWidth[i]] = true;
		for (int i = 0; i < x2; ++i) isMaxW[maxWidth[i]] = true;
		for (int i = 0; i < y1; ++i) isMinH[minHeight[i]] = true;
		for (int i = 0; i < y2 && !result; ++i) {
			int j = maxHeight[i];
			isMaxH[j] = true;
			result = isMinH[j] && isMaxH[j] && isMinW[j] && isMaxW[j];
		}
		if (result) printf("TAK\n");
		else printf("NIE\n");
	}
	return 0;
}