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

using namespace std;
int t,n,a,l,b,maksa,minia,maksb,minib,suma,sumb;
int tab[100000][3];
int main()
{
    cin>>t;
    for(t;t>0;t--){
        maksa = 0;
        minia = 1000000;
        maksb = 0;
        minib = 1000000;
        suma=0;
        sumb=0;
        cin>>n;
        for(int i = 0;i<n;i++){
            cin>>l>>a>>b;
            if(a>maksa){
                maksa=a;
            }
            if(a<minia){
                minia=a;
            }
            if(b>maksb){
                maksb=b;
            }
            if(b<minib){
                minib=b;
            }
            suma += a;
            sumb += b;
           /* tab[i][0]=l;
            tab[i][1]=a;
            tab[i][2]=b;
            if(tab[i][1])*/


        }
        if(maksa<maksb || minia>minib || suma != sumb){
            cout<<"NIE"<<endl;
        }
        else{
            cout<<"TAK"<<endl;
        }
        //cout<<minia<<endl<<maksa<<endl<<minib<<endl<<maksb;
    }
    return 0;
}