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

using namespace std;
typedef long long int LI;
typedef vector< LI > VLI;

string solve(const LI& N, const VLI& L, const VLI& A, const VLI& B)
{
    LI minB = B[0];
    LI maxB = B[0]; 
    LI minA = A[0];
    LI maxA = A[0];
    LI sumA = 0; 
    LI sumB = 0; 
    for (LI n = 0; n<N; ++n)
    {
        if (A[n] < minA) minA = A[n];
        else if (B[n] < minB) minB = B[n];
        if (A[n] > maxA) maxA = A[n];
        else if (B[n] > maxB) maxB = B[n];
        sumA += L[n]*A[n];
        sumB += L[n]*B[n];
    }
    if (sumA != sumB || minB < minA || maxB > maxA)
        return "NIE";
    return "TAK";
}

int main()
{
    LI T;
    cin >> T;
    vector< string > sol;
    for (LI t = 0; t<T; ++t)
    {
        VLI L, A, B;
        LI N, l, a, b;
        cin >> N;
        for (LI n = 0; n<N; ++n)
        {
            cin >> l >> a >> b;
            L.push_back(l);
            A.push_back(a);
            B.push_back(b);    
        }
        sol.push_back(solve( N, L, A, B));
    }
    for (LI t = 0; t<T; ++t)
    {
        cout << sol[t] << endl;
    }

    return 0;
}