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
#include <string>

using namespace std;

int main() {
	int t, test, n, i;
	int minW, maxW, minH, maxH;
	int fromW, toW, fromH, toH;
	int majorMinW = -1, majorMaxW = -1, majorMinH = -1, majorMaxH = -1;

	scanf("%d", &t);
	for (test = 0; test < t; ++test) {
		scanf("%d", &n);
		minW = 1000000001;
		maxW = 0;
		minH = 1000000001;
		maxH = 0;
		for (i = 0; i < n; ++i) {
			scanf("%d", &fromW);
			scanf("%d", &toW);
			scanf("%d", &fromH);
			scanf("%d", &toH);

			if (fromW < minW) minW = fromW;
			if (toW > maxW) maxW = toW;
			if (fromH < minH) minH = fromH;
			if (toH > maxH) maxH = toH;

			if (fromW == minW && toW == maxW && fromH == minH && toH == maxH) {
				majorMinW = fromW;
				majorMaxW = toW;
				majorMinH = fromH;
				majorMaxH = toH;
			}
		}

		// Decide if candidate is a true Major!
		if (majorMinW <= minW && majorMaxW >= maxW && majorMinH <= minH && majorMaxH >= maxH) {
			printf("%s\n", "TAK");
		} else {
			printf("%s\n", "NIE");
		}
	}

	return 0;
}