#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pii;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
int p[500005],b[500005],ans[500005],a[500005],dp[500005],c[500005];
int tot=0;
void sieve(){
p[1]=1;
for(int i=2;i<=500000;i++){
for(int j=2*i;j<=500000;j+=i)
p[j]=1;
}
for(int i=1;i<=500000;i++){
if(p[i]==0) b[++tot]=i;
}
}
void solve(){
int n,l;
int cnt=0;
cin>>n>>l;
char x;
for(int i=1;i<=n;i++){
cin>>x;
if(x=='1'){
a[++cnt]=i;
}
dp[i]=0;
ans[i]=0;
}
dp[0]=1;
if(l==0){
cout<<-1<<"\n";
return;
}
int totb=0;
for(int i=1;i<=tot;i++){
if(b[i]>l){
break;
}
if(l%b[i]==0) c[++totb]=b[i];
}
for(int i=1;i<=totb;i++){
if(c[i]>cnt){
break;
}
for(int j=c[i];j<=cnt;j++){
dp[j]|=dp[j-c[i]];
}
}
if(dp[cnt]) {
int now=cnt;
for(int i=totb;i>=1;i--){
if(c[i]>now){
continue;
}
while(dp[now]&&dp[now-c[i]]){
for(int j=now-c[i]+1;j<now;j++){
ans[a[j]]=a[j+1];
}
ans[a[now]]=a[now-c[i]+1];
now-=c[i];
}
if(now==0) break;
}
int head=0,fir=0;
for(int i=1;i<=n;i++){
if(!ans[i]&&head==0){
head=i;
fir=i;
}
else if(!ans[i]&&head){
ans[i]=head;
head=i;
}
}
ans[fir]=head;
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
cout<<"\n";
}
else{
cout<<-1<<"\n";
}
}
signed main(){
IOS;
int t=1;
sieve();
cin>>t;
while(t--){
solve();
}
return 0;
}