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
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
int n;
int a[1001000];
map<pii,int> Mp;
bool solve2(int cur,int delta,int nd)
{
	if(cur==nd)
	{
		if(a[cur]-delta==1) return true;
		return false;
	}
	int cnt=a[cur]-delta;
	if(cnt==a[cur+1]+1) return (cur+1==nd);
	if(cnt>a[cur+1]+1) return false;
	if(Mp.find(pii(cur,delta))!=Mp.end()) return Mp[pii(cur,delta)];
	return Mp[pii(cur,delta)]=solve2(cur+1,cnt-1,nd);
}
bool solve1(int cur,int delta,int nd)
{
	if(cur==nd)
	{
		if(a[cur]-delta==1) return true;
		return false;
	}
	int cnt=a[cur]-delta;
	if(solve2(cur,delta,nd)) return true;
	if(cnt>=a[cur+1]) return false;
	return solve1(cur+1,cnt,nd);
}
void solve()
{
	Mp.clear();
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int st=1,nd=n;
	while(!a[st]) st++;
	while(!a[nd]) nd--;
	cout<<(solve1(st,0,nd)?"TAK":"NIE")<<'\n';
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}