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
55
56
57
58
59
60
#include <cstdio>

bool is_major(long int* offer, long int* major_values)
{
	return (offer[0] == major_values[0]) && (offer[1] == major_values[1]) && (offer[2] == major_values[2]) && (offer[3] == major_values[3]);
}

long int max(long int a, long int b)
{
	if(a > b)
		return a;
	else
		return b;
}

long int min(long int a, long int b)
{
	if(a < b)
		return a;
	else
		return b;
}

int main()
{
	int t;
	scanf("%d", &t);
	for(int z = 0; z < t; ++z)
	{
		long int n;
		bool major = false;
		scanf("%d", &n);
		long int offer[4];
		long int major_values[4] = { 1000000001, 0, 1000000001, 0 };
		long int current_major_offer[4];
		for(long int i = 0; i < n; ++i)
		{
			scanf("%ld %ld %ld %ld", &offer[0], &offer[1], &offer[2], &offer[3]);
			major_values[0] = min(major_values[0], offer[0]);
			major_values[1] = max(major_values[1], offer[1]);
			major_values[2] = min(major_values[2], offer[2]);
			major_values[3] = max(major_values[3], offer[3]);
			if(is_major(offer, major_values))
			{
				major = true;
				current_major_offer[0] = offer[0];
				current_major_offer[1] = offer[1];
				current_major_offer[2] = offer[2];
				current_major_offer[3] = offer[3];
			}
			else
				major = is_major(current_major_offer, major_values);
		}
		if(major)
			printf("TAK\n");
		else
			printf("NIE\n");
	}
	return 0;
}