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
#include <iostream>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e5+10;
int n;
PII A[N], B[N];
LL a, b;

bool op(){
  cin >> n;
  a = b = 0;
  for(int i=1; i<=n; i++){
    cin >> A[i].second >> A[i].first >> B[i].first;
    B[i].second = A[i].second;
    a = a + (LL)((LL)A[i].first * (LL)A[i].second);
    b = b + (LL)((LL)B[i].first * (LL)B[i].second);
  }
  if(a!=b)return 0;
  sort(A+1,A+n+1);
  sort(B+1,B+n+1);
  for(int i=n; i>0; i--){
    if(A[i].first > B[i].first)return 1;
    if(A[i].first == B[i].first && A[i].second > B[i].second)return 1;
    if(A[i].first < B[i].first)return 0;
    if(A[i].first == B[i].first && A[i].second < B[i].second)return 0;
  }
  return 1;
}

int main(){
  boost;
  int t; cin >> t;
  while(t--) cout << (op() ? "TAK\n" : "NIE\n");
  return 0;
}