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
//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back

void solve(int ttt){
    int n;
	cin >> n;
	int a[n];
	rep(n) cin >> a[i];
	int s = 0;
	int k = n-1;
	for ( ; s<n ; s++){
		if (a[s]!=0) break;
	}
	for (; k>s ; k--){
		if (a[k]!=0) break;
	}
	for (; s<k ; s++){
		if (a[s]<a[s+1]){
			a[s+1]-=a[s];
			a[s]=0;
		}else{
			a[s] -= a[s+1]-1;
			a[s+1] = 1;
			break;
		}
	}
	for (; k>s ; k--){
		if (a[k]<a[k-1]){
			a[k-1] -= a[k];
			a[k] = 0;
		}else{
			a[k] -= a[k-1]-1;
			a[k-1] = 1;
			break;
		}
	}
	bool ok = 1;
	for (int i = s ; i<k ; i++){
		if (a[i]>=1 && a[i+1]>=1){
			if (a[i]>a[i+1]){
				a[i]-=a[i+1]-1;
				a[i+1] = 1;
			}else{
				a[i+1]-=a[i]-1;
				a[i] = 1;
			}
		}
		if (a[i]!=1) ok = 0;
	}
	if (ok&&a[k]==1) cout << "TAK\n";
	else cout << "NIE\n";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
    rep(t) solve(i);
}