#include<bits[表情]dc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
ll num[200005];
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll n,k,m;
cin>>n>>k>>m;
for(ll i=1;i<=n;i++)
{
cin>>num[i];
}
sort(num+1,num+1+n);
ll flag=0;
if(k&1)
{
for(ll i=1;i<=n;i++)
{
if(num[i]==m&&i-1>=(k-1)/2&&(n-i)>=(k-1)/2)
{
flag=1;
break;
}
}
}
else
{
for(ll i=1;i<=n;i++)
{
ll b=2*m-num[i];
ll u=lower_bound(num+i,num+1+n,b)-num;
//cout<<u<<"\n";
if(u==i)
{
u+=1;
}
if(u<=n&&num[u]==b&&(i-1)>=k/2-1&&n-u>=k/2-1)
{
flag=1;
break;
}
}
}
if(flag==1)
{
cout<<"TAK"<<"\n";
}
else
{
cout<<"NIE"<<"\n";
}
}
}