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

#define MAXDIM 1000000000
#define MIN(a,b) ((a)<(b))?(a):(b)
#define MAX(a,b) ((a)>(b))?(a):(b)

int main()
{
	int t;
	cin>>t;
	for (int i = 0; i < t; ++i)
	{
		int n;
		cin>>n;
		int majorwmin = MAXDIM;
		int majorwmax = 0;
		int majorhmin = MAXDIM;
		int majorhmax = 0;
		int mw1,mw2,mh1,mh2;
		
		for (int j = 0; j < n; ++j)
		{
			int w1,w2,h1,h2;
			cin>>w1>>w2>>h1>>h2;
			majorwmin = MIN(majorwmin,w1);
			majorwmax = MAX(majorwmax,w2);
			majorhmin = MIN(majorhmin,h1);
			majorhmax = MAX(majorhmax,h2);
			if((w1 == majorwmin)&&(w2 == majorwmax)&&(h1 == majorhmin)&&(h2 == majorhmax))
			{
				mw1 = w1;
				mw2 = w2;
				mh1 = h1;
				mh2 = h2;
			}
		}
		bool wynik=((mw1==majorwmin)&&(mw2==majorwmax)&&(mh1==majorhmin)&&(mh2==majorhmax));
		if(wynik) cout<<"TAK"; else cout<<"NIE";
		cout<<endl;
	}
}