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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <cstdio>

// POCZATEK szybkiego wczytywania

#define INPUT_BUFFER_SIZE 100000

inline char my_getchar()
{
	static char _input_buffer[INPUT_BUFFER_SIZE + 1];
	static int _buffer_pos = INPUT_BUFFER_SIZE;

	if (_buffer_pos == INPUT_BUFFER_SIZE) {
		int t = std::fread(_input_buffer, 1, INPUT_BUFFER_SIZE, stdin);
		_input_buffer[t] = EOF;
		_buffer_pos = 0;
	}
	return _input_buffer[_buffer_pos++];
}

inline void read_int(int &n)
{
	char c;
	bool read = false;
	n = 0;
	while (true) {
		c = my_getchar();
		if ('0' <= c && c <= '9') {
			read = true;
			n = 10 * n + c - '0';
		}
		else if (read || c == EOF) {
			break;
		}
	}
}
// KONIEC szybkiego wczytywania

int main()
{
	int t;
	read_int(t);

	for (; t > 0; t--) {
		int n;

		read_int(n);

		static int to_minimize1[100100], to_maximize1[100100], to_minimize2[100100], to_maximize2[100100];

		int to_minimize1_best = 2000000000;
		int to_maximize1_best = -1;
		int to_minimize2_best = 2000000000;
		int to_maximize2_best = -1;

		for (int i = 0; i < n; i++) {
			read_int(to_minimize1[i]); if (to_minimize1[i] < to_minimize1_best) to_minimize1_best = to_minimize1[i];
			read_int(to_maximize1[i]); if (to_maximize1[i] > to_maximize1_best) to_maximize1_best = to_maximize1[i];
			read_int(to_minimize2[i]); if (to_minimize2[i] < to_minimize2_best) to_minimize2_best = to_minimize2[i];
			read_int(to_maximize2[i]); if (to_maximize2[i] > to_maximize2_best) to_maximize2_best = to_maximize2[i];
		}

		bool res = false;
		for (int i = 0; i < n; i++) {
			if (to_minimize1[i] == to_minimize1_best
				&& to_maximize1[i] == to_maximize1_best
				&& to_minimize2[i] == to_minimize2_best
				&& to_maximize2[i] == to_maximize2_best) {
				res = true;
				break;
			}
		}

		if (res)
			std::puts("TAK");
		else
			std::puts("NIE");
	}
}