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
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n, b, l1, l2, l3, tpc = 0, tkc = 0, mxl2 = -1, mxl3 = -1, mnl2 = 1000001, mnl3 = 1000001;

    vector <int> prl2;
    vector <int> prl3;

    scanf("%lld", &n);

    for(int v = 0; v < n; v++)
    {
        scanf("%lld", &b);

        for(int i = 0; i < b; i++)
        {
            scanf("%lld" "%lld" "%lld", &l1, &l2, &l3);

            tpc += l2;
            tkc += l3;

            mxl2 = max(mxl2, l2);
            mxl3 = max(mxl3, l3);

            mnl2 = min(mnl2, l2);
            mnl3 = min(mnl3, l3);
        }

        if(tpc == tkc && mxl2 >= mxl3 && mnl2 <= mnl3)
            printf("%s", "TAK\n");
        else
            printf("%s", "NIE\n");

        tpc = 0;
        tkc = 0;
        mxl2 = -1;
        mxl3 = -1;
        mnl2 = 1000001;
        mnl3 = 1000001;
    }
}