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

int main(int argc, char* argv[]) {
	int times, companies, w1, w2, h1, h2, mw1, mw2, mh1, mh2;
	bool isMajor = true;
	scanf("%d", &times);
	for(int t = 0; t < times; t++) {
		scanf("%d", &companies);
		scanf("%d %d %d %d", &mw1, &mw2, &mh1, &mh2);
		for(int c = 1; c < companies; c++) {
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			bool iw1 = w1 < mw1, iw2 = w2 > mw2, ih1 = h1 < mh1, ih2 = h2 > mh2;
			if(isMajor) {
				if((iw1 || iw2 || ih1 || ih2) && (w1 > mw1 || w2 < mw2 || h1 > mh1 || h2 < mh2)) isMajor = false;
			} 
			else if(w1 <= mw1 && w2 >= mw2 && h1 <= mh1 && h2 >= mh2) {
				isMajor = true;
			}
			if(iw1) mw1 = w1;
			if(iw2) mw2 = w2;
			if(ih1) mh1 = h1;
			if(ih2) mh2 = h2;
		}
		printf("%s\n", isMajor ? "TAK" : "NIE");
	}
	
	return 0;
}