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>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define ST first
#define ND second
#define PB push_back

bool solve() {
    int n;
    cin >> n;
    vector<pll> v;
    ll s=0;
    for(int i=0; i < n; i++) {
        ll l, a, b;
        cin >> l >> a >> b;
        s+=l*(a-b);
        v.PB({a, l});
        v.PB({b, -l});
    }
    if(s != 0) {
        return false;
    }
    sort(v.begin(), v.end());
    s = 0;
    ll d = 0;
    for(int i=0; i < (int)v.size(); i++) {
        if(s < 0) {
            return false;
        }
        d+=v[i].ND;
        if(i+1 != (int)v.size()) {
            s+=(v[i+1].ST-v[i].ST)*d;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--) {
        bool res = solve();
        if(res) {
            cout << "TAK\n";
        } else {
            cout << "NIE\n";
        }
    }
}