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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct kubek {
  ll v;
  ll t;
  bool operator <(const kubek &rhs) const {
    return t < rhs.t;
  }
};
bool solve () {
  int n;
  cin >> n;
  vector<kubek> mam(n);
  vector<kubek> chce(n);
  ll l, a, b;
  ll E1 = 0, E2 = 0;
  ll w = 0;
  for (int i=0;i<n;i++) {
    cin >> l >> a >> b;
    mam[i] = {l, a};
    chce[i] = {l, b};
    E1 += l * a;
    E2 += l * b;
    w += l;
  }
  //cout<<E1<<" "<<E2<<endl;
  if (E1 != E2) return false;
  //for (auto i:mam) cout<<i.t<<" ";
  //cout<<endl;
  //for (auto i:chce) cout<<i.t<<" ";
  //cout<<endl;
  double E1dif = 0, E2dif = 0;
  //cout<<"###"<<endl;
  //cout<<s1<<" "<<s2<<endl;
  for (auto i:mam) E1dif += abs(E1 - w*i.t)*i.v;
  for (auto i:chce) E2dif += abs(E2 - w*i.t)*i.v;
  if (E1dif < E2dif) return false;
  return true;
}

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    if (solve()) cout<<"TAK\n";
    else cout<<"NIE\n";
  }
}