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
#include <cstdio>
#include <vector>
using namespace std;

#define FOR(i, p, k) for(int i = (p); i < (k); i++)
typedef pair<int, int> II;

int t, n;

struct Rect {
	int minw, maxw, minh, maxh;
};

Rect scanRect() {
	Rect r;
	scanf("%d %d %d %d", &r.minw, &r.maxw, &r.minh, &r.maxh);
	return r;
}

bool notSmaller(Rect min, Rect a) {
	if(a.minw <= min.minw && a.maxw >= min.maxw && a.minh <= min.minh && a.maxh >= min.maxh) {
		return true;
	}
	return false;
}

bool newMin(Rect &min, Rect a) { //czy a większy niż min
	bool newm = false;
	if(a.minw < min.minw) {
		min.minw = a.minw;
		newm = true;
	}
	if(a.maxw > min.maxw) {
		min.maxw = a.maxw;
		newm = true;
	}
	if(a.minh < min.minh) {
		min.minh = a.minh;
		newm = true;
	}
	if(a.maxh > min.maxh) {
		min.maxh = a.maxh;
		newm = true;
	}
	return newm;
}

int main() {
	scanf("%d", &t);
	FOR(ti, 0, t) {
		scanf("%d", &n);
		Rect min = scanRect();  //minimalne wymiary majoranty
		Rect major = min;
		bool ok = true; //istnieje major
		FOR(i, 1, n) {
			Rect a = scanRect();
			if(notSmaller(min, a)) { //a jest noweym majorem
				major = a;
				min = a;
				ok = true;
			}else if(newMin(min, a)) {
				ok = false;
			}else {
			}
		}
		if(ok) {
			printf("TAK\n");
		}else {
			printf("NIE\n");
		}
	}
	return 0;
}