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
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " " << x << endl;

#define int long long // uważaj

const int N = 1e6 + 7;

bool solve() {
    vector<pair<int, long long> > vek;
    map<int, long long> dodaj;

    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int l, a, b;
        cin >> l >> a >> b;
        vek.push_back({a, l});
        vek.push_back({b, -l});
    }

    sort(vek.begin(), vek.end());
    reverse(vek.begin(), vek.end());

    long long potencjal = 0;
    long long akt_ile = 0;
    for(int i = 0; i < vek.size(); i++) {
        if(potencjal < 0) return false;
        akt_ile += vek[i].second;
        int akt_temp = vek[i].first;

        if(i + 1 != vek.size()) potencjal += (akt_ile) * (akt_temp - vek[i + 1].first);
    }

    if(potencjal == 0) return true;
    return false;
}

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int test = 1;
    cin >> test;

	while(test--){
		if(solve()) cout << "TAK\n";
        else cout << "NIE\n";
	}

	return 0;
}