structOption { int x, y, typ; }q[max_n]; int n, m, a[max_n]; int cpy[max_n], tot, sum, rk[max_n]; int val[max_n]; ll bs[max_n], bv[max_n];
inlineintrd(){ registerint x = 0, c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return x; } inlinevoidadd(int x, int c, ll *b){ for (; x <= sum + 1; x += (x & -x)) b[x] += (ll)c; } inline ll query(int x, ll *b){ ll ret = 0; for (; x; x -= (x & -x)) ret += b[x]; return ret; }
intmain(){ n = rd(); m = rd(); char *line = newchar[5]; for (int i = 1; i <= m; ++i) { scanf("%s%d%d", line, &q[i].x, &q[i].y); if (line[0] == 'U') { q[i].typ = ++tot; cpy[tot] = rk[tot] = q[i].y; } else { q[i].typ = -1; } } sort(cpy + 1, cpy + 1 + tot); sum = int(unique(cpy + 1, cpy + 1 + tot) - (cpy + 1)); for (int i = 1; i <= tot; ++i) rk[i] = int(lower_bound(cpy + 1, cpy + 1 + sum, rk[i]) - cpy); for (int i = 1; i <= m; ++i) if (~q[i].typ) q[i].y = rk[q[i].typ]; for (int i = 1; i <= m; ++i) { if (~q[i].typ) { if (val[q[i].x] > 0) { int rkk = lower_bound(cpy + 1, cpy + 1 + sum, val[q[i].x]) - cpy; add(rkk + 1, -1, bs); add(rkk + 1, -val[q[i].x], bv); } val[q[i].x] = cpy[q[i].y]; if (val[q[i].x] > 0) { add(q[i].y + 1, 1, bs); add(q[i].y + 1, cpy[q[i].y], bv); } } else { int rkk = upper_bound(cpy + 1, cpy + 1 + sum, q[i].y) - cpy - 1; ll cnt = query(sum + 1, bs) - query(rkk + 1, bs); ll lower_sum = query(rkk + 1, bv); if (lower_sum >= (q[i].x - cnt) * (ll)q[i].y) puts("TAK"); elseputs("NIE"); } } return0; }