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

bool flag;
LL t, n, l, a, b, bilans;
vector <LL> A, B;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while(t--){
		cin>>n;
		bilans=0;
		for(int i=1;i<=n;i++){
			cin>>l>>a>>b;
			for(int j=1;j<=l;j++){
				A.push_back(a);
				B.push_back(b);		
			}
		}
		
		sort(A.begin(),A.end());
		sort(B.begin(),B.end());
		for(int i=0;i<A.size();i++){
			bilans+=B[i]-A[i];
			if(bilans<0)
				break;
		}
		A.erase(A.begin(),A.end());
		B.erase(B.begin(),B.end());
		if(bilans==0)
			cout<<"TAK"<<endl;
		else
			cout<<"NIE"<<endl;
	}
}