#include<bits/stdc++.h>
using namespace std;
vector<int> tab;
bool czy(int x,int n,int k)
{
vector<int> lis;
vector<int> dp(k+3,0);
for(int i = 0;i < n;++i)
{
if(tab[i] >= x)
{
lis.push_back(1);
}
else
{
lis.push_back(0);
}
}
for(int i = n-1;i >= 0;i--)
{
int j = i%k;
dp[j] = max(dp[j],dp[j+1] + lis[i]);
}
for(int i = 0;i < n;++i)
{
cout << dp[i] << ' ';
}
//cout << dp[k-1] << endl;
if(dp[0] >= ((n%k)+1)/2) return true;
return false;
//cout << dp[k-1] << endl;
}
int main()
{
int t;
cin >> t;
for(int q = 0;q < t;++q)
{
int n,k,x;
cin >> n >> k;
for(int i = 0;i < n;++i)
{
cin >> x;
tab.push_back(x);
}
cout << czy(4,n,k) << endl;
/*int l = 0,p=1000000003,mid;
while(l < p)
{
mid = (l+p+1)/2;
if(czy(mid,n,k))
{
l = mid;
}
else
{
p = mid-1;
}
}
cout << l << endl;*/
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZlY3RvcjxpbnQ+IHRhYjsKCmJvb2wgY3p5KGludCB4LGludCBuLGludCBrKQp7Cgl2ZWN0b3I8aW50PiBsaXM7Cgl2ZWN0b3I8aW50PiBkcChrKzMsMCk7Cglmb3IoaW50IGkgPSAwO2kgPCBuOysraSkKCXsKCQlpZih0YWJbaV0gPj0geCkKCQl7CgkJCWxpcy5wdXNoX2JhY2soMSk7CgkJfQoJCWVsc2UKCQl7CgkJCWxpcy5wdXNoX2JhY2soMCk7CgkJfQoJfQoJZm9yKGludCBpID0gbi0xO2kgPj0gMDtpLS0pCgl7CgkJaW50IGogPSBpJWs7CgkJZHBbal0gPSBtYXgoZHBbal0sZHBbaisxXSArIGxpc1tpXSk7Cgl9Cglmb3IoaW50IGkgPSAwO2kgPCBuOysraSkKCXsKCQljb3V0IDw8IGRwW2ldIDw8ICcgJzsKCX0KCS8vY291dCA8PCBkcFtrLTFdIDw8I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