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

int main()
{
	unsigned int numberOfTests;
	std::cin >> numberOfTests;
	for (unsigned int test=0; test<numberOfTests; ++test)
	{
		unsigned int numberOfOffers;
		std::cin >> numberOfOffers;
		unsigned int minW1 = 1000000001;
		unsigned int maxW2 = 0;
		unsigned int minH1 = 1000000001;
		unsigned int maxH2 = 0;
		bool answer = false;
		for (unsigned int offer=0; offer<numberOfOffers; ++offer)
		{
			unsigned int w1, w2, h1, h2;
			std::cin >> w1;
			std::cin >> w2;
			std::cin >> h1;
			std::cin >> h2;
			bool changed = false;
			if (w1 < minW1)
			{
				changed = true;
				minW1 = w1;
			}
			if (w2 > maxW2)
			{
				changed = true;
				maxW2 = w2;
			}
			if (h1 < minH1)
			{
				changed = true;
				minH1 = h1;
			}
			if (h2 > maxH2)
			{
				changed = true;
				maxH2 = h2;
			}
			bool candidate = (w1==minW1) and (w2==maxW2) and (h1==minH1) and (h2==maxH2);
			if (changed)
			{
				answer = candidate; 
			}
			else
			{
				answer = answer or candidate; 
			}
			
		}
		std::cout << (answer ? "TAK" : "NIE") << std::endl;
	}
	return 0;
}