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

int main(){
int t;
cin >> t;
for(int q=0; q<t; q++){
	long long suma_a=0;
	long long suma_b=0;
	int min_a=1000000;
	int min_b=1000000;
	int lmin_a=0;
	int lmin_b=0;
	int max_a=0;
	int max_b=0;
	int lmax_a=0;
	int lmax_b=0;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int l, a, b;
		cin >> l >> a >> b;
		suma_a=suma_a+(l*a);
		suma_b=suma_b+(l*b);
		if(a<min_a){
			lmin_a=l;
			min_a=a;
		}
		if(b<min_b){
			lmin_b=l;
			min_b=b;
		}
		if(b>max_b){
			lmax_b=l;
			max_b=b;
		}
		if(a>max_a){
			lmax_a=l;
			max_a=a;
		}
		
	}
if(suma_a!=suma_b || min_a>min_b || max_a<max_b){
	cout << "NIE" << endl;
}else{
	if(min_a==min_b && lmin_a!=lmin_b){
		cout << "NIE" << endl;
	}else{
	if(max_a==max_b && lmax_a!=lmax_b){
		cout << "NIE" << endl;
	}else{
		cout << "TAK" << endl;
	}
}
}
}
}