#include<iostream>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; ++i)
{
int numberOfChildren;
cin >> numberOfChildren;
long long actualSum = 0;
long long wantedSum = 0;
long long theColdestActual = 1000001;
long long theColdestWanted = 1000001;
long long theHotestActual = -1;
long long theHotestWanted = -1;
long long l, a, b;
long long difference = 0;
for(int j = 0; j < numberOfChildren; ++j)
{
cin >> l >> a >> b;
actualSum += l*a;
wantedSum += l*b;
difference += (b-a)*l;
if(theColdestActual > a)
theColdestActual = a;
if(theColdestWanted > b)
theColdestWanted = b;
if(theHotestActual < a)
theHotestActual = a;
if(theHotestWanted < b)
theHotestWanted = b;
}
//cout << actualSum << endl << theColdestActual << " "
// << theColdestWanted << endl << theHotestActual << " "
// << theHotestWanted << endl << difference << endl;
if(actualSum != wantedSum
|| theColdestWanted < theColdestActual
|| theHotestWanted > theHotestActual
|| difference != 0)
{
cout << "NIE\n";
continue;
}
cout << "TAK\n";
}
}