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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   Vi         = vector<int>;
using   Pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

using vec2 = pair<ll, ll>;

vec2 operator-(vec2 a, vec2 b) {
	return {a.x-b.x, a.y-b.y};
}

ll cross(vec2 a, vec2 b) {
	return a.x*b.y - a.y*b.x;
}

bool run() {
	int n; cin >> n;
	vector<vec2> hull[2];

	rep(i, 0, n) {
		ll l, a, b; cin >> l >> a >> b;
		hull[0].pb({l, l*a});
		hull[1].pb({l, l*b});
	}

	each(h, hull) {
		sort(all(h), [](vec2 a, vec2 b) { return cross(a, b) > 0; });
		rep(j, 1, sz(h)) {
			h[j].x += h[j-1].x;
			h[j].y += h[j-1].y;
		}
	}

	if (hull[0].back() != hull[1].back()) {
		return 0;
	}

	int j = 0;
	each(p, hull[1]) {
		while (hull[0][j].x < p.x) j++;

		vec2 prv = (j > 0 ? hull[0][j-1] : vec2(0, 0));

		vec2 hullVec = hull[0][j]-prv, toVec = p-prv;
		hullVec.y /= hullVec.x;
		hullVec.x = 1;

		if (cross(hullVec, toVec) < 0) return 0;
	}

	return 1;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(18);
	int t; cin >> t;
	while (t--) cout << (run() ? "TAK\n" : "NIE\n");
	return 0;
}