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

int main(){
	int t, n, W1, W2, H1, H2, w1, w2, h1, h2;
	cin.sync_with_stdio(false);	
	cin >> t;
	for (int i = 0; i < t; i++){
		cin >> n >> W1 >> W2 >> H1 >> H2;
		bool result = true;
		for (int j = 1; j < n; j++){
			cin >> w1 >> w2 >> h1 >> h2;
			if (w1<=W1 && w2>=W2 && h1<=H1 && h2>=H2){
				// rozszerzanie
				W1 = w1; W2 = w2; H1 = h1; H2 = h2;
				result = true;
				continue;
			}
			else if (w1>=W1 && w2<=W2 && h1>=H1 && h2<=H2){
				// zawieranie
			}
			else{
				// sprzecznosc
				if(w1<W1)W1=w1;
				if(w2>W2)W2=w2;
				if(h1<H1)H1=h1;
				if(h2>H2)H2=h2;
				result = false;
			}
		}
		if (result){
			cout << "TAK" << endl;
		}else{
			cout << "NIE" << endl;
		}
	}
	return 0;
}