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

int main()
{
ios_base::sync_with_stdio(0);
int n, k, i, l, t, p, min_p, min_k, maks_p, maks_k;
long long suma, wazona_pocz, wazona_kon;
cin >> t;
while(t--){
	cin >> n;
	suma = wazona_pocz = wazona_kon = maks_p = maks_k =0;
	min_p = min_k = 1000001;
	for(i = 0; i < n; i++){
		cin >> l >> p >> k;
		suma +=l; wazona_pocz += l*p; wazona_kon += l*k; 
		min_p = min(min_p, p); maks_p = max(maks_p, p);
		min_k = min(min_k, k); maks_k = max(maks_k, k); 	
	}
	//cout <<"min_p "<<min_p <<" maks_p "<<maks_p <<endl;
	//cout <<"min_k "<<min_k <<" maks_k "<<maks_k <<endl;
	//cout <<"wazona_pocz "<<wazona_pocz <<" wazona_kon "<<wazona_kon <<endl;
	if(wazona_pocz == wazona_kon && min_k >= min_p && maks_k <= maks_p){ 
			cout <<"TAK" << endl;
	}
	else {
		cout <<"NIE" << endl;
	}
}


return 0;
}