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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;


const int N=1e6+7;
int t, n, l, a, b;

long long sumaa=0; long long sumab=0;
int minia=N; int minib=N;
int maksa=0; int maksb=0;

int main() {

    ios_base::sync_with_stdio(false);

    cin >> t;
    for (int ii = 0; ii < t; ii++) {

        cin >> n;

        for (int i = 0; i < n; i++) {

            cin >> l >> a >> b;
            if (a < minia) minia = a;
            if (a > maksa) maksa = a;
            if (b < minib) minib = b;
            if (b > maksb) maksb = b;

            sumaa += a;
            sumab += b;

        }
        if (sumaa == sumab && minib >= minia && maksb <= maksa)
            cout << "TAK\n";
        else
            cout << "NIE\n";

        sumaa = 0;
        sumab = 0;
        minia = N;
        minib = N;
        maksa = 0;
        maksb = 0;
    }

}