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

using namespace std;

int l,a,b,t,n;
long long S;
int minia=1000001,maksa=0,minib=1000001,maksb=0;

int main()
{
    cin>>t;
    for (int i=0;i<t;i++)
    {
        cin>>n;
        for (int j=0;j<n;j++)
        {
            cin>>l>>a>>b;
            S+=(l*a)-(l*b);
            if (minia>a) minia=a;
            if (maksa<a) maksa=a;
            if (minib>b) minib=b;
            if (maksb<b) maksb=b;
        }
        if(S==0&&maksa>=maksb&&minia<=minib) cout<<"TAK\n";
            else cout<<"NIE\n";

        minia=minib=1000001;
        S=maksa=maksb=0;
    }
    return 0;
}