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 <cstdio>
#include <cmath>
#include <cassert>
#include <string>
//#define DEBUG

#ifdef DEBUG
#define D(x); x
#else
#define D(x);
#endif

using namespace std;

long long l[100002];
long long a[100002];
long long b[100002];

int main() {
  int t = 0;
  int n = 0;

  scanf("%d", &t);
  while(t--) {
    scanf("%d", &n);
    long long before = 0;
    long long after = 0;
    long long maxBefore = 0;
    long long maxAfter = 0;

    long long minBefore = 0;
    long long minAfter = 0;

    long long sum = 0;

    for(int i = 0; i < n; i++) {
      scanf("%lld %lld %lld", l + i, a + i, b + i);
      if(a[i] > maxBefore) maxBefore = a[i];
      if(b[i] > maxAfter) maxAfter = b[i];
      if(a[i] < minBefore || i == 0) minBefore = a[i];
      if(b[i] < minAfter || i == 0) minAfter = b[i];
      before += l[i] * a[i];
      after += l[i] * b[i];

      sum += l[i];
    }
    D(printf("before %lld after %lld (%lld, %lld) -> (%lld, %lld) sum %lld avg %f\n", before, after, minBefore, maxBefore, minAfter, maxAfter, sum, (before * 1.0 / sum)););
    if(before == after && maxBefore >= maxAfter && minBefore <= minAfter) printf("TAK\n"); else printf("NIE\n");
  }

  return 0;
}