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

vector <int> c;
vector <int> tc;

bool spr(int a, int b){
	if(tc[a] == 0){
		for(int i = 0; i < b; i++) if(tc[i] != 0) return false;
		return true;
	}
	if(a == 0 || (a < b - 1 && tc[a + 1] > tc[a - 1])){
		tc[a]--;
		return spr(a + 1, b);
	}
	else if(a == b - 1 || tc[a - 1] > tc[a + 1]){
		tc[a]--;
		return spr(a - 1, b);
	}
	else{
		tc[a]--;
		return spr(a - 1, b) || spr(a + 1, b);
	}
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a, b, tmp;
	bool f;
	cin >> a;
	for(int i = 0; i < a; i++){
		cin >> b;
		f = false;
		for(int j = 0; j < b; j++){ 
			cin >> tmp;
			c.push_back(tmp);
			tc.push_back(tmp);
		}
		for(int j = 0; j < b; j++){
			for(int k = 0; k < b; k++) tc[k] = c[k];
			if(spr(a, b)){
				f = true;
				break;
			}
		}
		if(f) cout << "TAK" << '\n';
		else cout << "NIE" << '\n';
	}
	return 0;
}