#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
typedef long long ll;
bool solve() {
int n;
cin >> n;
ll pa =0, pb = 0;
ll cntall = 0;
vector<pair<ll,ll> > A(n),B(n);
for(int i=0;i<n;i++) {
int l,a,b;
cin >> l >> a >> b;
cntall += l;
pa += l*a;
pb += l*b;
A[i] = {a,l};
B[i] = {b,l};
}
if(pa != pb) {
return false;
}
sort(A.begin(),A.end());
sort(B.begin(),B.end());
ll cntl = 0,suml = 0, cntr=0,sumr = 0;
for(int i=0;i<n;i++) {
sumr += A[i].st*A[i].nd;
cntr += A[i].nd;
}
int j = 0;
for(int i=0;i<n;i++) {
if(B[i].st*cntall <= pa) {
while(j < n && A[j].st <= B[i].st) {
sumr -= A[j].st*A[j].nd;
cntr -= A[j].nd;
suml += A[j].st*A[j].nd;
cntl += A[j].nd;
j++;
}
}
else {
while(j < n && A[j].st < B[i].st) {
sumr -= A[j].st*A[j].nd;
cntr -= A[j].nd;
suml += A[j].st*A[j].nd;
cntl += A[j].nd;
j++;
}
}
if(B[i].st*cntall <= pa) {
if((B[i].nd-cntl) > (B[i].st*cntl - suml)*(long double)cntr/(sumr-B[i].st*cntr)) {
return false;
}
}
else {
if((B[i].nd-cntr) > (sumr - B[i].st*cntr)*(long double)cntl/(B[i].st*cntl-suml)) {
return false;
}
}
}
return true;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--) {
if(solve())
cout<<"TAK\n";
else
cout<<"NIE\n";
}
}