#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,m;
cin>>n>>m;
int i,j;
vector a(n+1);
for( i=1;i<=n;i++){
cin>>a[i];
}
vector right(n+1,INT_MAX),left(n+1,INT_MAX);
int pre_right=-1;
for( i=1;i<=n;i++){
if(a[i]==1){
pre_right=i;
}
if(pre_right!=-1){
right[i]=i-pre_right;
}
}
int pre_left=-1;
for( j=n;j>=1;j–){
if(a[j]==2){
pre_left=j;
}
if(pre_left!=-1){
left[j]=pre_left-j;
}
}
while(m--){
int dest;
cin>> dest;
int ans=min(left[dest],right[dest]);
if(ans==INT_MAX){
ans=-1;
}
if(dest==1){
ans=0;
}
cout<<ans<<endl;
}
cout<<endl;
}
int main() {
int t;
cin>>t;
while(t–){
solve();
}
// your code goes here
return 0;
}