#include<bits/stdc++.h>
#define int long long
#define mem(x,y) memset(x,y,sizeof(x))
#define frein freopen("in.in","r",stdin)
#define freout freopen("out.out","w",stdout)
using namespace std;
int read(){
int s = 0,w = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
return s * w;
}
int t;
int n,m;
int a[1000010];
int sum;
int maxx;
int b[1000010];
int id[1000010];
int cnt;
int lst;
int l,r,mid;
signed main(){
cin>>t;
while(t --){
maxx = -2147483647;
lst = -2147483647;
cnt = 0;
sum = 0;
n = read(),m = read();
for(int i = 1;i <= n;i ++){
a[i] = read();
sum += a[i];
maxx = max(maxx,sum);
if(sum > lst){
b[++ cnt] = sum;
id[cnt] = i;
lst = sum;
}
}
while(m --){
int ans = 0;
int x;
x = read();
if(sum < 0){
cout<<-1<<" ";
continue;
}
if(maxx >= x){
l = 1;
r = cnt;
int s = lower_bound(b + 1,b + cnt + 1,x) - b;
ans += id[s];
cout<<ans - 1<<" ";
continue;
}
if(sum == 0){
if(maxx < x){
cout<<-1<<" ";
continue;
}
else {
l = 1;
r = cnt;
int s = lower_bound(b + 1,b + cnt + 1,x) - b;
ans += id[s];
cout<<ans - 1<<" ";
continue;
}
}
ans += (x - maxx + 1) / sum * n;
x = x - ((x - maxx + 1) / sum * sum);
if(x != 0){
l = 1;
r = cnt;
int s = lower_bound(b + 1,b + cnt + 1,x) - b;
ans += id[s];
}
cout<<ans - 1<<" ";
}
cout<<endl;
}
}