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
#include <iostream>
#include <assert.h>
#include <limits>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);

	int t;
	cin >> t;
	assert(1 <= t && t <= 10);
	while(t--)
	{
		int n;
		cin >> n;
		assert(2 <= n && t <= 100000);

		int gwmin = numeric_limits<int>::max();
		int gwmax = numeric_limits<int>::min();
		int ghmin = numeric_limits<int>::max();
		int ghmax = numeric_limits<int>::min();
		bool majorizer_present = false;
		for(int i=0; i<n; i++)
		{
			bool updated = false;
			int wmin, wmax, hmin, hmax;
			cin >> wmin >> wmax >> hmin >> hmax;
			assert(1 <= wmin);
			assert(wmin <= wmax);
			assert(wmax <= 1000000000);
			assert(1 <= hmin);
			assert(hmin <= hmax);
			assert(hmax <= 1000000000);
			if(wmin < gwmin)
			{
				gwmin = wmin;
				updated = true;
			}
			if(wmax > gwmax)
			{
				gwmax = wmax;
				updated = true;
			}
			if(hmin < ghmin)
			{
				ghmin = hmin;
				updated = true;
			}
			if(hmax > ghmax)
			{
				ghmax = hmax;
				updated = true;
			}
			bool equal =
					(gwmin == wmin) &&
					(gwmax == wmax) &&
					(ghmin == hmin) &&
					(ghmax == hmax);
			if(updated)
			{
				majorizer_present = equal;
			}
			else
			{
				majorizer_present = majorizer_present || equal;
			}
		}
		cout << (majorizer_present ? "TAK" : "NIE") << endl;
	}
	return 0;
}