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
76
77
78
79
80
#include <cstdio>
#include <vector>

void test_case() {
	int n, i, x, a, b;
	short stage;
	std::vector<int> c;
	scanf("%d", &n);
	c.reserve(n + 8);
	c.push_back(0);
	for (i = 0; i < n; ++i) {
		scanf("%d", &x);
		c.push_back(x);
	}
	c.push_back(0);
	c.push_back(0);
	n += 3;
	stage = 0;
	for (i = 0; i < n - 1; ++i) {
		a = c[i];
		b = c[i + 1];
		if (stage == 0) {
			if (a < b) {
				c[i] -= a;
				c[i + 1] -= a;
			}
			else if (a == b) {
				if (a) {
					c[i] = 0;
					c[i + 1] = 1;
					stage = 1;
				}
			}
			else if (a - b == 1) {
				c[i] = 0;
				c[i + 1] = 0;
				stage = 2;
			}
			else {
				printf("NIE\n");
				return;
			}
		}
		else if (stage == 1) {
			if (a < b) {
				c[i] -= a;
				c[i + 1] -= a - 1;
			}
			else if (a == b) {
				c[i] = 0;
				c[i + 1] = 1;
			}
			else if (a - b == 1) {
				c[i] = 0;
				c[i + 1] = 0;
				stage = 2;
			}
			else {
				printf("NIE\n");
				return;
			}
		}
		else {
			if (a || b) {
				printf("NIE\n");
				return;
			}
		}
	}
	printf("TAK\n");
}

int main () {
	int t, i;
	scanf("%d", &t);
	for (i = 1; i <= t; ++i) {
		test_case();
	}
	return 0;
}