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
#include <iostream>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	
	int t, n;
	cin >> t;
	
	for (int i = 0; i < t; i++) {
		cin >> n;
		int min0 = 1000001, max0 = -1, min1 = 1000001, max1 = -1, sum0 = 0, sum1 = 0;
		int l, a, b;
		
		for (int j = 0; j < n; j++) {
			cin >> l >> a >> b;
			
			if (a < min0) min0 = a;
			if (b < min1) min1 = b;
			if (a > max0) max0 = a;
			if (b > max1) max1 = b;
			sum0 += l * a;
			sum1 += l * b;
		}
		
		if (min0 > min1 || max0 < max1 || sum0 != sum1) {
			cout << "NIE\n";
		} else {
			cout << "TAK\n";
		}
	}
	
	return 0;
}