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
#include <iostream>

using namespace std;

bool do_test();


int main()
{
	ios_base::sync_with_stdio(0);
	
	int t;
	cin >> t;

	for(int i=0; i<t; i++)
	{
		if(do_test())
			cout << "TAK\n";
		else
			cout << "NIE\n";	
		
	}
	
	return 0;
}

// a,b,c,d zawiera a1,b1,c1,d1
inline bool contains(int a, int b, int c, int d, int a1, int b1, int c1, int d1)
{
	return a<=a1 && b>=b1 && c<= c1 && d>=d1;
}


bool do_test()
{
	int n;

	cin >> n;	
	
	int h1, h2, w1, w2; 
	int min_h1, max_h2, min_w1, max_w2; 
	int b_h1, b_h2, b_w1, b_w2; 

    cin >> min_w1 >> max_w2 >> min_h1 >> max_h2;
	b_h1 = min_w1;
	b_h2 = max_w2;
	b_w1 = min_h1;
	b_w2 = max_h2; 
	bool res = true;	
	
	for(int i=1; i<n; i++)
	{
		cin >> w1 >> w2 >> h1 >> h2;
		if(w1<min_w1)
				min_w1 = w1;
		if(h1<min_h1)
				min_h1 = h1;
		if(w2>max_w2)
				max_w2 = w2;
		if(h2>max_h2)
				max_h2 = h2;
				
		if(!res || !contains(b_h1, b_h2, b_w1, b_w2, min_h1, max_h2, min_w1, max_w2)) 
		{
			if(contains(h1, h2, w1, w2, h1, max_h2, min_w1, max_w2))
			{
				res = true;
				b_h1 = h1;
				b_h2 = h2;
				b_w1 = w1;
				b_w2 = w2;	
			}	
			else
				res = false;
		}		
	}	
	
	return res;
	
}