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

const int inf = 1000 * 1000 * 1000;
int maxW, maxH;
int minW, minH;
bool isAny;

void reset() {
	minW = minH = inf;
	maxW = maxH = -inf;
	isAny = false;
}

int w, W, h, H;

void update() {
	if(w < minW) {
		isAny = false;
		minW = w;
	}
	if(W > maxW) {
		isAny = false;
		maxW = W;
	}
	if(h < minH) {
		isAny = false;
		minH = h;
	}
	if(H > maxH) {
		isAny = false;
		maxH = H;
	}
}

void isThis() {
	if(!isAny)
		isAny = (w == minW) && (W == maxW)
			&& (h == minH) && (H == maxH);
}

int main() {
	int z;
	scanf("%d", &z);
	while(z--) {
		int n;
		scanf("%d", &n);
		reset();
		for(int i = 0; i < n; ++i) {
			scanf("%d%d%d%d", &w, &W, &h, &H);
			update();
			isThis();
		}
		printf("%s\n", isAny ? "TAK" : "NIE");
	}
	return 0;
}