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

#define FOR(i,l,r) for(int i = (l); i <= (r); i++)
#define FORD(i,l,r) for(int i = (l); i >= (r); i--)

using num = double;
using ind = long long;

bool solve2(vector<int> v){
    int n = v.size()-1;
    FOR(i,1,n-1){
        if(v[i] > v[i+1]) return false;
        else{
            v[i+1] -= v[i];
            v[i]=0;
        }
    }
    if(v[n]!=0) return false;
    return true;
}
void solve(){
    int n;
    cin >> n;
    vector<int> vt;
    vt.resize(n+1);
    FOR(i,1,n){
        cin >> vt[i];
    }
    int first_no_zero=n+1;
    int last_no_zero=-1;
    FOR(i,1,n){
        if(vt[i]!=0){
            first_no_zero = min(first_no_zero,i);
            last_no_zero = max(last_no_zero,i);
        }
    }
    vector<int> v;
    vector<int> v1;
    vector<int> v2;
    vector<int> v3;
    v.push_back(0);
    v1.push_back(0);
    v2.push_back(0);
    v3.push_back(0);
    FOR(i,first_no_zero,last_no_zero){
        v.push_back(vt[i]-1);
        v1.push_back(vt[i]-1);
        v2.push_back(vt[i]-1);
        v3.push_back(vt[i]-1);
    }
    v1[1]++;
    v2[v2.size()-1]++;
    v3[1]++;
    v3[v3.size()-1]++;
    if(solve2(v)) {cout << "TAK\n"; return;}
    if(solve2(v1)) {cout << "TAK\n"; return;}
    if(solve2(v2)) {cout << "TAK\n"; return;}
    if(solve2(v3)) {cout << "TAK\n"; return;}
    cout << "NIE\n"; return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--){
        solve();
    }
}