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
#include<iostream>

using namespace std;


int main () {

	int t = 0;
	cin >> t;
	
	int maxTemp1 = 0, maxTemp2 = 0;
	unsigned long long  vol1 = 0, vol2 = 0;
	for (int i = 0; i < t; i++) {
		
		unsigned long long expectedTemp = 0, startingTemp = 0;
		
		maxTemp1 = 0;
		maxTemp2 = 0;
		vol1 = 0;
		vol2 = 0;
		
		int n = 0;
		cin >> n;
		
		for (int j = 0; j < n; j++) {
			
			int l = 0, a = 0, b = 0;
			cin >> l >> a >> b;
			
			expectedTemp += l * b;
			startingTemp += l * a;
			
			if (maxTemp1 < a) {
				maxTemp1 = a;
				vol1 = l;
			} else if (maxTemp1 == a) {
				vol1 += l;
			}
			
			if (maxTemp2 < b) {
				maxTemp2 = b;
				vol2 = l;
			} else if (maxTemp2 == b) {
				vol2 += l;
			}
		}
		
		if (expectedTemp != startingTemp || maxTemp2 > maxTemp1 || (maxTemp2 == maxTemp1 && vol2 > vol1) ) {
			cout << "NIE" << endl;
			continue;
		}
		cout << "TAK" << endl;
	}
}