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

int cur;

void update(int* value, int* mvalue, bool& exists, bool& majorizes, int& sign) {
	cur = sign*(*value - *mvalue);
	if (cur < 0) {
		*mvalue = *value;
		exists = false;
	}
	else if (cur > 0) {
		majorizes = false;
	}
}

int main() {

	int value[4], mvalue[4];
	int t, n, sign = 1;
	bool exists = false, majorizes = false;
	string result;
	scanf("%d", &t);

	for (int i = 0; i < t; i++) {
		scanf("%d", &n);
		mvalue[0] = mvalue[2] = 1000000001;
		mvalue[1] = mvalue[3] = -1000000001;
		exists = false;
		for (int j = 0; j < n; j++) {
			scanf("%d %d %d %d", &value[0], &value[1], &value[2], &value[3]);
			majorizes = true;
			for (int k = 0; k < 4; k++) {
				update(&value[k], &mvalue[k], exists, majorizes, sign);
				sign = sign * -1;
			}
			if (majorizes) exists = true;
		}
		if (exists) result = "TAK";
		else result = "NIE"; 
		printf("%s\n", result.c_str());
	}
}