// Problem: G - Data Determination
// Contest: Virtual Judge - The 3rd Universal Cup. Stage 8: Cangqian + The 3rd Universal Cup. Stage 7: Warsaw
// URL: https://vjudge.net/contest/658753#problem/G
// Memory Limit: 1014 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
#define int long long
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
void solve()
{
int n , k , m;
cin >> n >> k >> m;
int ok = 0;
set<int>st;
int a[n];
for(int i = 0 ; i < n ; i ++){
cin >> a[i];
st.insert(a[i]);
}
map<int,int>mp;
map<int,int>pm;
int id = 0;
for(auto it : st){
mp[it] = ++id;
pm[id] = it;
}
vector<int>cnt(id + 5 , 0);
vector<int>pre(id + 5 , 0);
for(int i = 0 ; i < n ; i++){
pre[mp[a[i]]]++;
cnt[mp[a[i]]]++;
}
for(int i = 1 ; i <= id ; i ++){
pre[i] += pre[i - 1];
}
if(k & 1){
int le = k / 2;
int ri = k / 2;
if(!mp.count(m)){
cout << "NIE\n";
}
else{
if(pre[mp[m] - 1] < le){
cnt[mp[m]] -= le - pre[mp[m] - 1];
}
if(pre[id] - pre[mp[m]] < ri){
cnt[mp[m]] -= ri - pre[id] + pre[mp[m]];
}
if(cnt[mp[m]] > 0){
cout <<"TAK\n";
}
else{
cout <<"NIE\n";
}
}
}
else{
int l = 1 , r = id;
while(l <= r){
while(pm[l] + pm[r] < m * 2){
l++;
}
if(pm[l] + pm[r] > m * 2){
r--;
continue;
}
else{
int le = k / 2 - 1;
int ri = k / 2 - 1;
int ok = 1;
if(l == r){
if( cnt[l] < 2 + max(0LL , le - pre[l - 1]) + max(0LL , ri - pre[id] + pre[r])){
ok = 0;
}
}
if(pre[l - 1] < le){a
if(cnt[l] <= le - pre[l - 1]){
ok = 0;
}
}
if(pre[id] - pre[r] < ri){
if(cnt[r] <= ri - pre[id] + pre[r]){
ok = 0;
}
}
if(ok){
cout << "TAK\n";
return;
}
else{
r--;
}
}
}
cout <<"NIE\n";
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(10);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}