#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int MAXN = 1e5+4;
int t, n;
long long l[MAXN], a[MAXN], b[MAXN];
int main()
{
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%lld%lld%lld", &l[i], &a[i], &b[i]);
long long res1 = 0, res2 = 0;
for(int i = 1; i <= n; i++)
res1 += l[i] * a[i], res2 += l[i] * b[i];
if(res1 != res2) {
printf("NIE\n");
continue;
}
sort(a+1, a+n+1);
sort(b+1, b+n+1);
if(a[1] <= b[1] && b[n] <= a[n])
printf("TAK\n");
else
printf("NIE\n");
}
}