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

const int ene = 1e6+3;
int v[ene];

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while(t)
  {
    t--;
    int n;
    cin >> n;
    int bilans = 0;
    int m = 0;
    for(int i = 0; i < n; i++)
    {
      int a,b,p;
      cin >> p >> a >> b;
      bilans+=p*a;
      bilans-=p*b;
      v[a]+=p;
      v[b]-=p;
      m = max(m,max(a,b));
    }
    bool wyp = 0;
    if(bilans == 0)
    {
      for(int j = m; j > 0; j--)
      {
        if(v[j]>0)
        {
          cout << "TAK\n";
          wyp = 1;
          break;
        }
        if(v[j] < 0)
        {
          cout << "NIE\n";
          wyp = 1;
          break;
        }
      }
      if(!wyp)cout << "TAK\n";
    }
    else cout << "NIE\n";
    for(int  i = m; i >= 0; i--)v[i] = 0;
  }
  return 0;
}