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

using namespace std;

int main(){int q; cin >> q; for(int qq = 0; qq < q; qq ++){

	
	
	int sum = 0, min = 1000000, max = 0;
	int sum1 = 0, min1 = 1000000, max1 = 0;
	
	int n;
	cin >> n;
	for(int x = 0; x < n; x ++){
		int a, b, c;
		cin >> a >> b >> c;
		if(b < min)
			min = b;
		if(c < min1)
			min1 = c;
		if(b > max)
			max = b;
		if(c > max1)
			max1 = c;
		sum += a*b;
		sum1 += a*c;
		
	}
	
	//cout << sum << " " << sum1 << " " << min << " " << min1;
	if(sum == sum1 && min <= min1 && max >= max1)
		cout << "TAK";
	else
		cout << "NIE";
	cout << endl;
	
	
	
}}