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
#include <iostream>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int t;
	unsigned long n, w1, w2, h1, h2;
	unsigned long wi1= -1, wi2 = -1, he1 = -1, he2 = -1;
	bool wynik = false;
	cin >> t;
	for(int i = 0; i < t; i++){
		cin >> n;
		for( int j = 0 ; j < n; j++)
		{
			cin >> w1 >> w2 >> h1 >> h2;

			if(!j) { wi1 = w1; wi2 = w2; he1 = h1; he2 = h2;}
			else if ( wi1 <= w1 && wi2 >= w2 && he1 <= h1 && he2 >= h2) wynik= true;
			else if ( wi1 >= w1 && wi2 <= w2 && he1 >= h1 && he2 <= h2){
				wynik = true;
				wi1 = w1; wi2 = w2; he1 = h1; he2 = h2;
			} else { wynik = false;}
		}
		if(wynik) cout << "TAK" << endl; else cout << "NIE" << endl;
	}
	return 0;
}