#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define F(i,k,n) for(int i = k ; i < n ; ++i)
#define sz(x) (int)x.size()
#define var(x) #x << " " << x
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<LL> VLL;
const int INF=1e9+7,N=1e6+7;
LL a,b,c,d,l,n,m,t,k,wyn=0;
int main() {
boost;
cin >> t;
while(t--){
cin >> n;
LL sum_in=0,sum_out=0;
map<LL,LL> map_in,map_out;
vector<PLL> in,out;
for(int i=0;i<n;i++){
cin >> l >> a >> b;
sum_in+=l*a;
sum_out+=l*b;
map_in[a]+=l;
map_out[b]+=l;
}
if(sum_out!=sum_in){
cout << "NIE\n";
continue;
}
for(auto it=map_in.begin();it!=map_in.end();++it){
a=min(it->nd,map_out[it->st]);
map_out[it->st]-=a;
if(it->nd-a)
in.pb({it->st,it->nd-a});
}
for(auto it=map_out.begin();it!=map_out.end();++it)
if(it->nd)
out.pb({it->st,it->nd});
/* for(int i=0;i<sz(in);i++)
cout << "\tin[ " << i << " ] = { " << in[i].st << " , " << in[i].nd << " }\n";
for(int i=0;i<sz(out);i++)
cout << "\tout[ " << i << " ] = { " << out[i].st << " , " << out[i].nd << " }\n";*/
if((sz(in)==0)||(in[0].st<out[0].st && in.back().st>out.back().st)){
cout << "TAK\n";
continue;
}
cout << "NIE\n";
/*
int l=0,r=0,s=0;
while(r<sz(in) && out[0].st>=in[r].st){
r++;
}
cout << "\tpoczatkowe r:\t" r << "\n";
while(r<sz(in)){
a=min(in[l].nd,in[r].nd);
in[l].nd-=a;
in[r].nd-=a;
}*/
/*if()
cout << "TAK\n";
else
cout << "NIE\n";*/
}
}