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
#include <iostream>

using namespace std;

int main()
{
    long long L, N, Ai, Bm, Cm, A, B[100000+5], C[100000+5], Sb, Sc;
    cin >> L;
    for(int i=1; i<=L; ++i)
    {
        Ai=1;
        Bm=1000000+5;
        Cm=1000000+5;
        Sb=0;
        Sc=0;
        cin >> N;
        for(int i=1; i<=N; ++i)
        {
            cin >> A;
            cin >> B[i];
            cin >> C[i];
            if(Bm>B[i])
                Bm=B[i];
            if(Cm>C[i])
                Cm=C[i];
            B[i]=B[i]*A;
            C[i]=C[i]*A;
            Ai=Ai*A;
        }
        if(Bm>Cm)
            cout << "NIE" << endl;
        else
        {
            for(int i=1; i<=N; ++i)
            {
                Sb=B[i]*Ai+Sb;
                Sc=C[i]*Ai+Sc;
            }
            if(Sb==Sc)
                cout << "TAK" << endl;
            else
                cout << "NIE" << endl;
        }
    }
    return 0;
}