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
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main() {

	std::ios::sync_with_stdio(false);
	int test_no, kids_no;
	int litrs, actual_t, desire_t;
	int min_actual_t, max_actual_t, min_desire_t, max_desire_t;
	long long sum_l, sum_r;
	int hotter, colder;
	vector<int> act_v_vec;
	vector<int> des_v_vec;

	cin >> test_no;

	for (int i = 0; i < test_no; ++i) {

		cin >> kids_no;
		sum_l = 0, sum_r = 0;
		hotter = 0, colder = 0;
		min_actual_t = 1000000;
		max_actual_t = 0;

		min_desire_t = 1000000;
		max_desire_t = 0;
		
		act_v_vec.clear();
		des_v_vec.clear();

		for (int j = 0; j < kids_no; ++j) {
			cin >> litrs;
			cin >> actual_t;
			cin >> desire_t;

			sum_l += litrs * actual_t;
			sum_r += litrs * desire_t;

			act_v_vec.push_back(actual_t);
			des_v_vec.push_back(desire_t);

			if (actual_t < min_actual_t)
				min_actual_t = actual_t;

			if (actual_t > max_actual_t)
				max_actual_t = actual_t;

			if (desire_t < min_desire_t)
				min_desire_t = desire_t;

			if (desire_t > max_desire_t)
				max_desire_t = desire_t;
		}


		sort(act_v_vec.begin(), act_v_vec.end());
		sort(des_v_vec.begin(), des_v_vec.end());

		for (int j = 0; j < kids_no; ++j) {

			if (act_v_vec[j] < des_v_vec[j])
				colder += 1;
			if (act_v_vec[j] > des_v_vec[j])
				hotter += 1;
		}


		if (min_actual_t > min_desire_t || max_actual_t < max_desire_t || colder != hotter) {
			cout << "NIE" << endl;
		}
		else {
			if (sum_l == sum_r) {
				cout << "TAK" << endl;
			}
			else {
				cout << "NIE" << endl;
			}
		}

	}
}