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


int main() {
	long t;
	scanf("%ld\n", &t);
	for (int i=0;i<t;i++) {
		long k;
		
		long mw1=-1,mw2=-1,mh1=-1,mh2=-1;
		bool best=true;
		scanf("%ld\n", &k);
		for (int j=0; j<k; j++) {
			long w1,w2,h1,h2;
			scanf("%ld %ld %ld %ld\n", &w1, &w2, &h1, &h2);
			if (mw1 < 0) {
				best = true;
				mw1=w1; mw2=w2; mh1=h1; mh2=h2;
				//printf("st %ld %ld %ld %ld\n", mw1, mw2, mh1, mh2);
			} else {
				if (w1<=mw1 && w2>=mw2 && h1<=mh1 && h2>=mh2) {
//znalezlismy najlepszego
				//	printf("cu1 %ld %ld %ld %ld\n", mw1, mw2, mh1, mh2);
				//	printf("up1 %ld %ld %ld %ld\n", w1, w2, h1, h2);
					best = true;
					mw1=w1;mw2=w2;mh1=h1;mh2=h2;
				} else if (w1>=mw1 && w2<=mw2 && h1>=mh1 && h2<=mh2) {
// nic sie nie zmienia
				} else {
//ktorys wymiar wystaje
				//	printf("cu2 %ld %ld %ld %ld\n", mw1, mw2, mh1, mh2);
				//	printf("up2 %ld %ld %ld %ld\n", w1, w2, h1, h2);
					best = false;
					mw1=min(mw1,w1);
					mw2=max(mw2,w2);
					mh1=min(mh1,h1);
					mh2=max(mh2,h2);
				}
			}
			
		}

		//printf("%ld %ld %ld %ld\n", mw1, mw2, mh1, mh2);
		if(best) {
			printf("TAK\n");
		} else {
			printf("NIE\n");
		}
	}

	return 0;
}