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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;
int z, n;
int p, a ,b;
int e1, e2, m1, m2, M1, M2, pm1, pm2, pM1, pM2;
int main(){
    ios_base::sync_with_stdio(0);
    cin >> z;
    for(int x = 0; x < z; x++){
        e1 = 0;
        e2 = 0;
        m1 = 1e9; m2 = 1e9;
        M1 = 0; M2 = 0;
        pm1 = 0; pm2 = 0; pM1 = 0; pM2 = 0;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> p >> a >> b;
            e1 += p*a;
            e2 += p*b;
            if(a == m1) pm1 += p;
            if(a < m1){
                m1 = a;
                pm1 = p;
            }
            if(b == m2) pm2 += p;
            if(b < m2){
                m2 = b;
                pm2 = p;
            }
            if(a == M1) pM1 += p;
            if(a > M1){
                M1 = a;
                pM1 = p;
            }
            if(b == M2) pM2 += p;
            if(b > M2){
                M2 = b;
                pM2 = p;
            }
        }
        if(e1 == e2){
            if(m2 < m1 || M2 > M1){
                cout << "NIE\n";
            }
            else{
                if((m1 == m2 && pm2 > pm1) || (M1 == M2 && pM2 > pM1)){
                    cout << "NIE\n";
                }
                else{
                    cout << "TAK\n";
                }
            }
        }
        else{
            cout << "NIE\n";
        }
    }
}