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 <algorithm>
#include <vector>

using namespace std;

const int MX = 1e5+10;

int n, w1[MX], w2[MX], h1[MX], h2[MX], wmin, wmax, hmin, hmax;

bool solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d%d%d", &w1[i], &w2[i], &h1[i], &h2[i]);
		if (i == 1) {
			wmin = wmax = w1[i];
			hmin = hmax = h1[i];
		}
		wmin = min(wmin, w1[i]);
		wmax = max(wmax, w2[i]);
		hmin = min(hmin, h1[i]);
		hmax = max(hmax, h2[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (w1[i] == wmin && w2[i] == wmax && h1[i] == hmin && h2[i] == hmax) return true;
	}
	return false;
}

int main() {
	int t; scanf("%d", &t);
	while (t--) {
		printf(solve() ? "TAK\n" : "NIE\n");
	}
	return 0;
}