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

const ll N = ((int)(1e6))+50;
const ll M = ((int)(1e7))+50;

ll n,x;
bool superCase = true;
ll l[N] , a[N] , b[N];

int main(){
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>x;
	while(x--){
		ll sumTp = 0;
		ll sumTk = 0;
		ll minTp = M;
		ll minTk = M;
		ll maxTp = -M;
		ll maxTk = -M;
		cin>>n;
		for (int i = 0; i < n; i++){
			cin>>l[i]>>a[i]>>b[i];
			if(a[i] != b[i]){
				sumTp += l[i] * a[i];
				sumTk += l[i] * b[i];
				maxTp = max(maxTp , a[i]);
				maxTk = max(maxTk , b[i]);
				minTp = min(minTp , a[i]);
				minTk = min(minTk , b[i]);			
			}
			if(l[i] != 1){
				superCase = false;
			}
		}
		if(sumTp != sumTk){
			cout<<"NIE"<<endl;
			continue;
		} else {
			if(minTp <= minTk && maxTp >= maxTk){
				cout<<"TAK"<<endl;
			} else {
				cout<<"NIE"<<endl;
				continue;
			}
		}
	}
}