#include <iostream>
using namespace std;
int main() {
int t;
long long l, a, b, balance;
int n, lowest_a, highest_a, lowest_b, highest_b;
cin>>t;
for(int i = 0; i < t; i++){
balance = 0;
lowest_a = 10000000;
highest_a = -1;
lowest_b = 10000000;
highest_b = -1;
cin>>n;
for(int j = 0; j < n; j++){
cin>>l>>a>>b;
balance += l*a;
balance -= l*b;
if(a < lowest_a){
lowest_a = a;
}
if(a > highest_a){
highest_a = a;
}
if(b < lowest_b){
lowest_b = b;
}
if(b > highest_b){
highest_b = b;
}
}
if(balance == 0 && (lowest_a <= lowest_b) && (highest_a >= highest_b)){
cout<<"TAK"<<endl;
}
else{
cout<<"NIE"<<endl;
}
}
return 0;
}