#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_KIDS = 256 * 1000;
pair<int, int> it[MAX_KIDS];
bool solve() {
int gl;
cin >> gl;
int it_size = 2 * gl;
int vl, ts, te;
for (int i = 0; i < gl; ++i) {
cin >> vl >> ts >> te;
it[2 * i] = { ts, vl };
it[2 * i + 1] = { te, -vl };
}
sort(it, it + it_size);
int pos = it_size - 1;
ll balance = 0;
ll volume = it[pos].second;
while (--pos >= 0) {
balance += volume * (it[pos + 1].first - it[pos].first);
if (balance < 0) {
return false;
}
volume += it[pos].second;
}
return balance == 0;
}
int main() {
ios_base::sync_with_stdio(0);
int tc;
cin >> tc;
for (int i = 0; i < tc; ++i) {
cout << (solve() ? "TAK" : "NIE") << endl;
}
return 0;
}