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
79
80
81
82
83
84
85
/*
 *  Copyright (C) 2014  Paweł Widera
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details:
 *  http://www.gnu.org/licenses/gpl.html
 */
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;


class Factory {
public:
	unsigned long long w_min;
	unsigned long long w_max;
	unsigned long long h_min;
	unsigned long long h_max;

	Factory(unsigned long long w1, unsigned long long w2, unsigned long long h1, unsigned long long h2):
		w_min(w1), w_max(w2), h_min(h1), h_max(h2) {}

	void update(const Factory& other) {
		w_min = min(w_min, other.w_min);
		h_min = min(h_min, other.h_min);
		w_max = max(w_max, other.w_max);
		h_max = max(h_max, other.h_max);
	}

	bool operator==(const Factory& other) const {
		if (w_min == other.w_min && h_min == other.h_min &&
			w_max == other.w_max && h_max == other.h_max) {
			return true;
		}
		return false;
	}
};


int main() {
	int t;
	int n;
	unsigned long long w_min, w_max, h_min, h_max;
	vector<Factory> factories;

	ios::sync_with_stdio (false);
	cin >> t;

	for (int i = 0; i < t; ++i) {
		cin >> n;
		factories.resize(n, Factory(0,0,0,0));

		auto winner = Factory(1000000000, 1, 1000000000, 1);

		for (int j = 0; j < n; ++j) {
			cin >> w_min >> w_max >> h_min >> h_max;

			factories[j] = Factory(w_min, w_max, h_min, h_max);
			winner.update(factories[j]);
		}

		auto clear_winner = false;
		for (auto factory : factories) {
			if (factory == winner) {
				clear_winner = true;
				break;
			}
		}

		if (clear_winner) {
			cout << "TAK" << endl;
		} else {
			cout << "NIE" << endl;
		}
	}
	return 0;
}