#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
bool testcase() {
int n;
scanf("%d", &n);
vector<pll> av;
vector<pll> bv;
for (int i = 1; i <= n; i++) {
int l, a, b;
scanf("%d%d%d", &l, &a, &b);
av.push_back(make_pair(a, l));
bv.push_back(make_pair(b, l));
}
sort(av.begin(), av.end());
sort(bv.begin(), bv.end());
ll bal = 0;
int ptra = 0;
int ptrb = 0;
ll vola = av[0].second;
ll volb = bv[0].second;
while (ptra < n && ptrb < n) {
ll am = min(vola, volb);
bal += am * (bv[ptrb].first - av[ptra].first);
if (bal < 0) return false;
vola -= am;
volb -= am;
if (vola == 0) {
ptra++;
if (ptra < n) vola = av[ptra].second;
}
if (volb == 0) {
ptrb++;
if (ptrb < n) volb = bv[ptrb].second;
}
}
return true;
}
int main() {
int $;
scanf("%d", &$);
while ($--) {
puts(testcase() ? "TAK" : "NIE");
}
}