1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while (t--) {
        int n; cin >> n; long long aa = 0, bb = 0; int mina = 1000000, minb = 1000000, maxa = 0, maxb = 0;
        for (int i = 0; i < n; i++) {
            int l, a, b; cin >> l >> a >> b;
            aa += l * a; bb += l * b;
            if (a < mina) mina = a;
            if (a > maxa) maxa = a;
            if (b < minb) minb = b;
            if (b > maxb) maxb = b;
        }
        if (aa != bb || mina > minb || maxa < maxb) cout << "NIE" << endl;
        else cout << "TAK" << endl;
    }
    return 0;
}