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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAX_KIDS = 256 * 1000;

pair<int, int> it[MAX_KIDS];

bool solve() {
	int gl;
	cin >> gl;
	int it_size = 2 * gl;

	int vl, ts, te;
	for (int i = 0; i < gl; ++i) {
		cin >> vl >> ts >> te;
		it[2 * i] = { ts, vl };
		it[2 * i + 1] = { te, -vl };
	}

	sort(it, it + it_size);

	int pos = it_size - 1;
	ll balance = 0;
	ll volume = it[pos].second;
	while (--pos >= 0) {
		balance += volume * (it[pos + 1].first - it[pos].first);

		if (balance < 0) {
			return false;
		}

		volume += it[pos].second;
	}

	return balance == 0;
}

int main() {
	ios_base::sync_with_stdio(0);

	int tc;
	cin >> tc;
	for (int i = 0; i < tc; ++i) {
		cout << (solve() ? "TAK" : "NIE") << endl;
	}

	return 0;
}