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
#include <stdio.h>
#include <algorithm>
#include <limits>

const int MAXN = 100 * 1000;

/*struct window_t {
	int w1, w2;
	int h1, h2;
} windows[MAXN];*/

int h1[MAXN], h2[MAXN], w1[MAXN], w2[MAXN];

bool alg(int n) {
	int v_max = std::numeric_limits<int>::max(),
	    v_min = std::numeric_limits<int>::min();

	int c_h1 = v_max, c_h2 = v_min,
	    c_w1 = v_max, c_w2 = v_min;
	/*window_t w_max = {
		std::numeric_limits<int>::max(), std::numeric_limits<int>::min(),
		std::numeric_limits<int>::max(), std::numeric_limits<int>::min()
	};*/


	for (int i=0; i<n; ++i) {
		scanf("%i%i%i%i", &w1[i], &w2[i], &h1[i], &h2[i]);

		c_w1 = std::min(c_w1, w1[i]);
		c_h1 = std::min(c_h1, h1[i]);
		c_w2 = std::max(c_w2, w2[i]);
		c_h2 = std::max(c_h2, h2[i]);
	}

	bool is = false;
	for (int i=0; i<n; ++i) {
		if (w1[i] == c_w1 && w2[i] == c_w2 &&
				h1[i] == c_h1 && h2[i] == c_h2) {
			is = true;
			break;
		}
	}

	return is;
}

int main() {
	int t;
	scanf("%i", &t);
	while (t-->0) {
		int n;
		scanf("%i", &n);
		printf("%s\n", alg(n) ? "TAK" : "NIE");	
	}

	return 0;
}