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

using namespace std;

int main()
{
int t;
int n;
long long l, p, k;
long long s1 = 0;
long long s2 = 0;
int mn1 = INT_MAX, mx1=INT_MIN, mn2=INT_MAX, mx2=INT_MIN;
scanf("%d", &t);
for(int i = 0; i < t; ++i){
    mn2 = INT_MAX;
    mn1 = INT_MAX;
    mx1=-INT_MIN;
    mx2=-INT_MIN;

    s1 = 0;
    s2 = 0;
    scanf("%d", &n);
    for(int j = 0; j < n; ++j){
        scanf("%lld%lld%lld", &l, &p, &k);
        s1+=l * p;
        s2+=l * k;
        if(mn1 > p)
            mn1 = p;
        if(mx1 < p)
            mx1 = p;
        if(mn2 > k)
            mn2 = k;
        if(mx2 < k)
            mx2 = k;

    }
    //./cout<<s1<<" "<<s2<<" "<<mn1<<" "<<mn2<<" "<<mx1<<" "<<mx2<<endl;
    if(s1 == s2 && mn1 <= mn2 && mx1 >=mx2)
        printf("TAK\n");
    else
        printf("NIE\n");

}


    return 0;
}