#include <cstdio>
#include <algorithm>
#define T first
#define L second
using namespace std;
using LL = long long;
using PLL = pair<LL, LL>;
const int N = 1e5;
int n;
PLL a[N], b[N];
int main() {
int t; scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%lld%lld%lld", &a[i].L, &a[i].T, &b[i].T);
b[i].L = a[i].L;
}
sort(a, a+n);
sort(b, b+n);
LL l = 0, e = 0;
int i = 0, j = 0;
while (j < n) {
while (i < n && e + a[i].L * a[i].T <= (l + a[i].L) * b[j].T) {
l += a[i].L;
e += a[i].L * a[i].T;
++i;
}
// printf("%lld %lld %d\n", l, e, i);
if ((i < n && l * a[i].T - e >= b[j].L * (a[i].T - b[j].T)) || (i == n && e == l * b[j].T)) {
l -= b[j].L;
e -= b[j].L * b[j].T;
++j;
} else break;
}
puts(j == n ? "TAK" : "NIE");
}
return 0;
}