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

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}
int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

int testTea() {
    int avgStart = 0;
    int avgEnd = 0;
    int maxStart = 0;
    int maxEnd = 0;
    int minStart = INT_MAX;
    int minEnd = INT_MAX;
    int n, l, a, b;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> l;
        cin >> a;
        cin >> b;
        avgStart += l * a;
        avgEnd += l * b;
        maxStart = max(maxStart, a);
        minStart = min(minStart, a);
        maxEnd = max(maxEnd, b);
        minEnd = min(minEnd, b);
    }
    if (avgStart == avgEnd && maxStart >= maxEnd && minStart <= minStart)
        return true;
    return false;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int x = testTea();
        if (x)
            cout << "TAK";
        else
            cout << "NIE";
        cout << '\n';
    }
    return 0;
}