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
55
//Filip Wilkowski XIII LO w Szczecinie

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int n;
vector<LL> l, a, b;

bool check_vxt(){
	LL sum_a = 0, sum_b = 0;
	for(int i = 0; i < n; ++i){
		sum_a += a[i] * l[i];
		sum_b += b[i] * l[i];
	}

	return sum_a == sum_b;
}

bool check_t(){
	LL max_a = 0, min_a = LLONG_MAX;

	for(LL u:a){
		max_a = max(u, max_a);
		min_a = min(u, min_a);
	}

	for(LL u:b)
		if(u < min_a || u > max_a)
			return false;
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	while(t--){
		cin >> n;
		l.resize(n);
		a.resize(n);
		b.resize(n);

		for(int i = 0; i < n; ++i)
			cin >> l[i] >> a[i] >> b[i];

		if(check_t() && check_vxt())
			cout << "TAK\n";
		else
			cout << "NIE\n";
	}
}