#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=2e5+100;
int a[N];
int b[N];
int n,m,mx=0,sum=0;
int sol(int x)
{
    if(x<=mx){
        int v=0;
        for(int i=1;i<=n;i++){
            v+=a[i];
            if(v>=x){
                return i-1;
            }
        }
    }
    if(sum<=0)return -1;
    int l=1,r=1e9,ans;
    while(l<=r){
        int mid=(l+r)/2;
        if(sum*mid+mx>=x){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    int me=sum*ans;
    int v=n*ans-1;
    l=1,r=n,ans;
    while(l<=r){
        int mid=(l+r)/2;
        if(me+b[mid]>=x){
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }

    return v+ans;
}

void solve()
{
    mx=0,sum=0;
    scanf("%lld",&n);
    scanf("%lld",&m);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=b[i-1]+a[i];
        sum+=a[i];
        mx=max(mx,sum);
    }
    for(int i=1;i<=n;i++)b[i]=max(b[i],b[i-1]);
    while(m--){
        int x;
        scanf("%lld",&x);
        printf("%lld ",sol(x));
    }
    printf("\n");
}
main()
{
    //int co=2e5*log2(1e9);
    //cout<<co<<endl;
    //freopen("lasers.in","r",stdin);freopen("lasers.out","w",stdout);
    int t=1;
    cin>>t;
    while(t--)solve();
}
