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() {
	ios_base::sync_with_stdio(0);
	int ile;
	cin >> ile;
	for (int i=0; i<ile; i++) {
		long long unsigned t;
		cin >> t;
		long long unsigned wmin, wmax, hmin, hmax;
		cin >> wmin >> wmax >> hmin >> hmax;
		bool flag = true;
		for (long long unsigned j=0; j<t-1; j++) {
			long long unsigned twmin, twmax, thmin, thmax;
			cin >> twmin >> twmax >> thmin >> thmax;
			
			if (twmin<=wmin&&twmax>=wmax&&thmin<=hmin&&thmax>=hmax) flag = true;
			else if (twmin<wmin||twmax>wmax||thmin<hmin||thmax>hmax) flag = false;
		
			if (twmin<wmin) {
				wmin=twmin;
			}
			if (twmax>wmax) {
				wmax=twmax;
			}
			if (thmin<hmin) {
				hmin=thmin;
			}
			if (thmax>hmax) {
				hmax=thmax;
			}
		}
		if (flag) cout << "TAK" << endl;
		else cout << "NIE" << endl;
	}
	return 0;
}