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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>

using namespace std;

struct X
{
	long w1;
	long w2;
	long h1;
	long h2;
};

int main()
{
	short t = 0;
	long n = 0;

	X x;

	x.w1 = 0; 
	x.w2 = 0;
	x.h1 = 0;
	x.h2 = 0;

	long w_min = 0; 
	long w_max = 0;
	long h_min = 0;
	long h_max = 0;

	X* a = NULL; 

	cin >> t;

	for(int i=0; i<t; i++)
	{
		cin >> n;
		
		a = new X[n]; 

		for(long j=0; j<n; j++)
		{
			cin >> x.w1;
			cin >> x.w2;
			cin >> x.h1;
			cin >> x.h2;

			if(j == 0)
			{
				w_min = x.w1;
				w_max = x.w2;
				h_min = x.h1;
				h_max = x.h2;
			}
			else
			{
				w_min = w_min < x.w1 ? w_min : x.w1;
				w_max = w_max > x.w2 ? w_max : x.w2;
				h_min = h_min < x.h1 ? h_min : x.h1;
				h_max = h_max > x.h2 ? h_max : x.h2;
			}

			a[j] = x; 
		}

		bool result = false;

		for(long j=0; j< n; j++)
		{
			if(a[j].w1 == w_min && a[j].w2 == w_max && a[j].h1 == h_min && a[j].h2 == h_max)
				result = true;
		}

		if(result == true)
			cout << "TAK" << endl;
		else
			cout << "NIE" << endl;

		delete [] a;  
		a = NULL;
	}

	return 0;
}