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
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <iostream>
#include <vector>


using namespace std;



struct wyniki
{
	int a;
	int b;
	
	wyniki(int _a, int _b):a(_a),b(_b)
	{
		
		
	}
};

struct figura
{
	int top;
	int right;
	int left;
	int bottom;
};


class CLustra 
{
	private:
		int min_h,min_w,max_h,max_w;
	public:
		CLustra(int w, int ww, int h, int hh): min_h(h),min_w(w),max_h(hh),max_w(ww)
		{
		}
		CLustra(){};

		

		int Roznica_W(){
			return max_w-min_w;
		}
		int Roznica_H(){
			return max_h-min_h;
		}



		~CLustra(){};

		
};

class LustraMenager
{
private:
	vector <CLustra*> Dane;
	vector <wyniki*> w;
	vector <int> hitA;
	
public:

	LustraMenager(){};
	~LustraMenager(){Clean();};

	void Dodaj(int w, int ww, int h, int hh){
		Dane.push_back(new CLustra(w,ww,h,hh));
	}

	void Clean(){
		for( int i=0;i<Dane.size();i++){
			delete  Dane[i];
			Dane.clear();
		}
		for(int i=0;i<w.size();i++){
			delete  w[i];
			w.clear();
			
		}
	}
	
		void Look(){
			
			int a=Dane.size();
			for(int i=0; i<a;i++)
			{
				w.push_back(new wyniki(Dane[i]->Roznica_W(),Dane[i]->Roznica_H()));
			}
		}

		void show(){
			for(int a=0;a<w.size();a++){
				cout<<"Width: "<<w[a]->a<<endl<<"Height: "<<w[a]->b<<endl;
			}
		}


		void Test(){
			int max_h=0;
			int max_w=0;
			int indeks=0;
			int size = w.size();
			bool hit=false;
			for(int i=0;i<size;i++){
				if(w[i]->a > max_w)
				{
					max_w=w[i]->a;
					indeks=i;
				}
				if((w[i]->a == max_w) && (w[i]->b > w[indeks]->b)){
					indeks=i;
				}
			}
			
			for(int i=0;i<size;i++){
				
				if(w[i]->b > w[indeks]->b){
					hit=true;
					break;
				}
			}
			if(hit)cout<<"NIE"<<endl;
			else cout<<"TAK"<<endl;
			
		}

		

};









int main()
{
	int a,b,c,d[4];
	cin.sync_with_stdio(false);

	cin >>a;
	
	LustraMenager * TEST = new LustraMenager[a];
	for(int i=0;i<a;i++){
	
		cin>>b;
	
		for(int j=0;j<b;j++){
				cin>>d[0] >> d[1] >> d[2] >> d[3];
				
				TEST[i].Dodaj(d[0],d[1],d[2],d[3]);
		}
			

	}
	for(int i=0;i<a;i++){
	TEST[i].Look();
	TEST[i].Test();
	}
	

	
	
	return 0;
}