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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int t, n;

struct {
	bool operator()(pair<int, int> a, pair<int, int> b) const {   
	if(a.second==b.second) return a.first<b.first;
		return a.second > b.second;
	}   
} x;
struct {
	bool operator()(pair<int, int> a, pair<int, int> b) const {   
	if(a.second==b.second) return a.first>b.first;
		return a.second > b.second;
	}   
} y;

int l1, a1, b1;
vector<pair<int, int>> v1, v2;

int main(){
	scanf("%d", &t);
	while(t--){
		bool r=true;
		scanf("%d", &n);
		v1.clear();
		v2.clear();
		
		long long s1=0, s2=0;
		for(int i=1; i<=n; i++){
			scanf("%d %d %d", &l1, &a1, &b1);
			s1+=l1*a1;
			s2+=l1*b1;
			
			v1.push_back(make_pair(l1*a1, a1));
			v2.push_back(make_pair(l1*b1, b1));
			
		}
		if(s2!=s1){
			printf("NIE\n");
			continue;
		}
		sort(v1.begin(), v1.end(), y);
		sort(v2.begin(), v2.end(), x);
		if(v1.begin()->second < v2.begin()->second || v1.back().second>v2.back().second){
			r=false;
		}else if(v1.begin()->second == v2.begin()->second && v1.back().second == v2.back().second){
				r=(v1.begin()->first >= v2.begin()->first && v1.back().first >= v2.back().first);
		}else if(v1.begin()->second == v2.begin()->second && v1.back().second < v2.back().second){
			r = (v1.begin()->first >= v2.begin()->first);
		}else if(v1.begin()->second > v2.begin()->second && v1.back().second == v2.back().second){
			r = (v1.back().first >= v2.back().first);
		}else{
			r=true;
		}
		if(r){
			printf("TAK\n");
		}else{
			printf("NIE\n");
		}
		
	}
	return 0;
	
}