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
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

typedef long long int64;

using namespace std;

int main () {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; ++i) {
		int n, w1, h1, w2, h2, mw1, mh1, mw2, mh2;
		bool ok = true;
		scanf("%d", &n);
		scanf("%d %d %d %d", &mw1, &mw2, &mh1, &mh2);
		for (int j = 1; j < n; ++j) {
			scanf("%d %d %d %d", &w1, &w2, &h1, &h2);
			if (w1 <= mw1 && w2 >= mw2 && h1 <= mh1 && h2 >= mh2) {
				ok = true;
			}
			else if (w1 < mw1 || w2 > mw2 || h1 < mh1 || h2 > mh2) {
				ok = false;
			}
			mw1 = min(w1, mw1);
			mw2 = max(w2, mw2);
			mh1 = min(h1, mh1);
			mh2 = max(h2, mh2);
		}
		printf(ok ? "TAK\n" : "NIE\n");
	}
	return 0;
}