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
#include <stdio.h>

int n,t;

int main()
{
	int mina,maxa,minb,maxb,i;
	int l,a,b;
	long long int Ea,Eb;
	
	scanf("%d",&t);

	while(t--)
	{
		scanf("%d",&n);
		Ea=0;  Eb=0; 
		mina=1000001; maxa=0;
		minb=1000001; maxb=0;
		for(i=0;i<n;++i)
		{
			scanf("%d %d %d",&l,&a,&b);
			if(mina>a) mina=a;
			if(minb>b) minb=b;
			if(maxa<a) maxa=a;
			if(maxb<b) maxb=b;
			Ea += l*a;
			Eb += l*b;
		}
		if((Ea==Eb) && (mina<=minb) && (maxa>=maxb)) printf("TAK\n"); else printf("NIE\n");
	}

	return 0;
}