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
#include <iostream>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int t, n, maxW, minW, maxH, minH, w1, w2, h1, h2;
	bool r;

	cin >> t;

	while(t--)
	{
		cin >> n;

		n--;
		cin >> minW >> maxW >> minH >> maxH;
		r = true;

		while(n--)
		{
			cin >> w1 >> w2 >> h1 >> h2;
			
			if( (w1<=minW && w2>=maxW) && (h1<=minH && h2 >= maxH) )
				r=true;
			else
				if( (w1<minW || w2>maxW) || (h1<minH || h2 >maxH) )
					r=false;

			if(w1<minW)minW=w1;
			if(w2>maxW)maxW=w2;
			if(h1<minH)minH=h1;
			if(h2>maxH)maxH=h2;
		}

		if(r)cout << "TAK\n";
		else cout << "NIE\n";
	}

	return 0;
}