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

using namespace std;
int n,z,mn1, mn2, mx1,mx2, s1,s2,a,b,l;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   cin>>n;
   for(int i=0; i^n; ++i)
   {
       mx1=0;
       mx2=0;
       s1=0;
       s2=0;
       mn1=3457465;
       mn2=3457465;
       cin>>z;
       for(int j=0; j^z; ++j)
       {
           cin>>l>>a>>b;
           if (a>mx1) mx1=a;
           if (b>mx2) mx2=b;
           if (a<mn1) mn1=a;
           if (b<mn2) mn2=b;
           s1+=l*a;
           s2+=l*b;
       }
       if (s1!=s2) {cout<<"NIE"<<endl; continue;}
       if (mx2>mx1) {cout<<"NIE"<<endl; continue;}
       if (mn2<mn1) {cout<<"NIE"<<endl; continue;}
       cout<<"TAK"<<endl;
   }
 

}