1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<bits/stdc++.h>

using namespace std;

int main(){
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        long long s1=0, s2=0;
        int maxA=0, minA=1000001, maxB=0, minB=1000001;
        for(int i=0; i<n; i++) {
            int a, b, l;
            cin >> l >> a >> b;
            s1 += a*l;
            s2 += b*l;
            if(maxA < a) maxA = a;
            if(minA > a) minA = a;
            if(maxB < b) maxB = b;
            if(minB > b) minB = b;
        }

        if(s1 == s2 && maxA >= maxB && minA <= minB) cout << "TAK\n";
        else cout << "NIE\n";
    }
}