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
#include<bits/stdc++.h>
using namespace std;
#define nd second
#define st first
int temp=1000000;
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
	int sumaa=0,sumab=0;
	int n;
	cin>>n;
	pair<int,int> taba[n];
	pair<int,int> tabb[n];
	for(int z=0;z<n;z++){
		int l,a,b;
		cin>>l>>a>>b;
		taba[z].nd=l;
		taba[z].st=a;
		tabb[z].nd=l;
		tabb[z].st=b;
		sumaa=sumaa+a*l;
		sumab=sumab+b*l;
	}
	sort(taba,taba+n);
	sort(tabb,tabb+n);
	if(tabb[n-1].st<=taba[n-1].st&&tabb[0].st>=taba[0].st&&sumaa==sumab){
		cout<<"TAK"<<endl;
	}
	else{
		cout<<"NIE"<<endl;
	}

}
return 0;
}