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

using namespace std;

bool isMajor(int a, int b, int &gA, int &gB) {
	bool result = true;

	if(a > gA)
		result = false;
	else
		gA = a;

	if(b < gB)
		result = false;
	else
		gB = b;

	return result;
}

int main()
{
	int t,n;
	int wmin, wmax, hmin, hmax;
	int w1,w2,h1,h2;
	bool result, isMajorWidth, isMajorHeight;

	scanf("%d",&t);
	while( t-- != 0 ) {
		result = false;
		wmax = hmax = INT_MIN;
		wmin = hmin = INT_MAX;

		scanf("%d",&n);
		while( n-- != 0) {
			scanf("%d%d%d%d", &w1, &w2, &h1, &h2);
			isMajorWidth = isMajor(w1,w2,wmin,wmax);
			isMajorHeight = isMajor(h1,h2,hmin,hmax);

			if( isMajorWidth | isMajorHeight ) {
				if( !(isMajorWidth & isMajorHeight) ) {
					result = false;
				} else {
					result = true;
				}
			}
		}

		puts(result ? "TAK" : "NIE");
	}

	return 0;
}