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
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		LL sumLeft = 0;
		LL sumRight = 0;
		
		LL mini1 = 1000001;
		LL mini2 = 1000001;

		LL maxi1 = 0;
		LL maxi2 = 0;

		bool b = 1;

		for (int j = 0; j < n; j++) {
			LL weight, tend, tbegin;
			cin >> weight >> tbegin >> tend;
			sumLeft += weight * tend;
			sumRight += weight * tbegin;

			mini1 = min(mini1, tbegin);
			mini2 = min(mini2, tend);

			maxi1 = max(maxi1, tbegin);
			maxi2 = max(maxi2, tend);

		}
		cout << ( (b && mini1 <= mini2 && maxi1 >= maxi2 && sumLeft == sumRight) ? "TAK" : "NIE") << '\n';

	}

}