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

using namespace std;

int main() {
	int z;
	scanf("%d", &z);
	while (z--) {
		int n;
		scanf("%d", &n);
		int x_min, x_max, y_min, y_max;
		bool reached = true;
		scanf("%d%d%d%d", &x_min, &x_max, &y_min, &y_max);
		--n;
		while (n--) {
			int a, b, c, d;
			scanf("%d%d%d%d", &a, &b, &c, &d);
			if (a <= x_min && b >= x_max && c <= y_min && d >= y_max) {
				reached = true;
				x_min = a;
				x_max = b;
				y_min = c;
				y_max = d;
				continue;
			}
			if (a >= x_min && b <= x_max && c >= y_min && d <= y_max)
				continue;
			reached = false;
			x_min = min(a, x_min);
			x_max = max(b, x_max);
			y_min = min(c, y_min);
			y_max = max(d, y_max);
			
		}
		printf("%s\n", reached ? "TAK" : "NIE");
	}
}