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
50
51
52
53
54
#include <bits/stdc++.h>

#define pb push_back
#define pf push_front
#define turbo cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define fi first
#define sc second
#define ll long long
#define mp make_pair
#define un unsigned

#define debug 0

using namespace std;

int main()
{
    turbo
    int t;
    cin>>t;
    while(t--){
        
        int n,
            l,
            a,
            b;
        
        ll asuma=0;
        ll bsuma=0;
        int amin=INFINITY;
        int bmin=INFINITY;
        int amax=0;
        int bmax=0;
        
        cin>>n;
        
        while(n--){
            cin>>l>>a>>b;
            asuma+=a;
            bsuma+=b;
            amin=min(amin,a);
            bmin=min(bmin,b);
            amax=max(amax,a);
            bmax=max(bmax,b);
        }
        
        if(bmin<amin or bmax>amax){
            cout<<"NIE\n";
            continue;
        }
        cout<<"TAK\n";
    }
    return 0;
}