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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define INT(x) int x; scanf("%d", &x)

typedef long long LL;

int main() {
	INT(n);
	INT(q);
	LL s = 0;
	REP(i,n-1) {
		INT(u);
		INT(v);
		INT(w);
		s += w;
	}
	REP(qq,q) {
		INT(a);
		INT(b);
		INT(c);
		printf(a + b + c <= 5 * s / 6 ? "TAK\n" : "NIE\n");
	}
}