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
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpii vector<pair<int, int>>
#define str string
#define vs vector<str>
#define lli long long int
#define vc vector<char>
#define vvc vector<vc>


int main() {

    std::ios_base::sync_with_stdio(false);

    lli t;
    cin >> t;
    while (t--)
    {
        lli n;
        cin >> n;

        lli actual = 0, wanted = 0, maxac = 0, minac = 2000000, maxwan = 0, minwan = 2000000;
        for (int i = 0; i < n; i++) {
            lli l, a, b;

            cin >> l >> a >> b;
            actual += l * a;
            wanted += l * b;

            if (a > maxac)
                maxac = a;
            if (a < minac)
                minac = a;
            if (b > maxwan)
                maxwan = b;
            if (b < minwan)
                minwan = b;
        }

        if (actual == wanted && maxac >= maxwan && minac <= minwan)
            cout << "TAK" << endl;
        else 
            cout << "NIE" << endl;

    }
    return 0;
}