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;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,int> pill;
const int MAXN=2e5+6;

int t,n;
pill c[MAXN];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>t;
    ll l,a,b;
    while(t--){
        cin>>n;
        FOR(i,0,n){
            cin>>l>>a>>b;
            c[i*2]=MP(a,l);
            c[i*2+1]=MP(b,-l);
        }
        n*=2;
        sort(c,c+n);

        bool can=true;
        ll en=0;
        ll sum=c[n-1].ND;
        FORD(i,n-2,0){
            en+=sum*(c[i+1].ST-c[i].ST);
            sum+=c[i].ND;
            if(en<0){
                can=false;
                break;
            }
        }
        if(can&&en==0)cout<<"TAK\n";
        else cout<<"NIE\n";
    }
    return 0;
}