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
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e6+2;

int n, a[MAXN], in_l[MAXN], in_r[MAXN], out_l[MAXN], out_r[MAXN];

void solve () {
	cin >> n;
	a[0] = a[n + 1] = 0;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
		
	bool exists = 0;
	
	for (int s = 1; s <= n; s++) {
		for (int e = 1; e <= n; e++) {
			bool ok = 1;
			
			for (int i = 1; i <= n; i++)
				in_l[i] = in_r[i] = out_l[i] = out_r[i] = 0;
				
			in_r[1] = a[1] - (1 == s);
			out_r[1] = a[1] - (1 == e);
			
			for (int i = 2; i <= n; i++) {
				in_l[i] = out_r[i - 1];
				in_r[i] = a[i] - in_l[i] - (i == s);
				out_l[i] = in_r[i - 1];
				out_r[i] = a[i] - out_l[i] - (i == e);
			}
			
			if (in_l[1]) ok = 0;
			if (out_r[n]) ok = 0;
			for (int i = 1; i <= n; i++) {
				if (in_l[i] < 0 || in_r[i] < 0) ok = 0;
				if (out_l[i] < 0 || out_r[i] < 0) ok = 0;
				if (a[i] && s < i && !in_l[i]) ok = 0;
				if (a[i] && i < s && !in_r[i]) ok = 0;
				if (a[i] && e < i && !out_l[i]) ok = 0;
				if (a[i] && i < e && !out_r[i]) ok = 0;
			}

			if (ok) {
				exists = 1;
				break;
			}
		}
	}
	
	
	cout << (exists ? "TAK\n" : "NIE\n");
}


int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int tt; cin >> tt;
	while (tt--) solve();
}