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
#include <bits/stdc++.h>
using namespace std;

const int MAX_TEMP = 1000001;
int t, n;
int min_a, min_b, max_a, max_b;
long long diff_a_b;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> t;
	for (int test = 0; test < t; test++) {
// 		vector<int> temp(MAX_TEMP);
		
		min_a = MAX_TEMP; min_b = MAX_TEMP;
		max_a = 0; max_b = 0;
		diff_a_b = 0;
		
		cin >> n;
		for (int i = 0; i < n; i++) {
			int l, a, b;
			cin >> l >> a >> b;
			max_a = max(a, max_a);
			max_b = max(b, max_b);
			min_a = min(a, min_a);
			min_b = min(b, min_b);
			diff_a_b += l * (a - b);
// 			temp[a] += l;
// 			temp[b] -= l;
		}
		
		if (max_b > max_a || min_b < min_a || diff_a_b != 0)
			cout << "NIE" << endl;
		else {
// 			for (int i = min(min_a, min_b); i <= max(max_a, max_b); i++)
// 				if (temp[i] != 0) //TODO lol
					
			cout << "TAK" << endl;
		}
	}
}