#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std;
using namespace __gnu_pbds;
// Policy based data structure 
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
#define ll long long int
#define pii pair<ll,ll>
#define rep(i,st,en) for(ll i=st;i<en;i++)
#define vi vector<ll>
#define vii vector<pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define eb emplace_back
#define yes cout<<"YES"<<endl; return;
#define no cout<<"NO"<<endl; return;
#define flus fflush(stdout);
#define gin(x) cerr<<#x<<" : "<<x<<" ";
#define fin cerr<<endl;
#define F first
#define S second
#define np next_permutation
#define inf 1e12
#define mod 1000000007
#define N 200009
#define PI 3.14159265358979323846
#define minpq priority_queue <ll, vector<ll>, greater<ll>>
#define maxpq priority_queue<ll> 
void sout(){
    cout<<endl;
}
template <typename T,typename... Types>
void sout(T var1,Types... var2){
    cout<<var1<<" ";
    sout(var2...);
}

ll n,m;
ll a[N],x[N];
vii pre;
ll totalSum;

ll findMaxIterations(ll y){
    // find max iterations s.t. sum is lesser/equal to y
    ll ans=inf;
    ll l=0,r=inf;
    while(l<=r){
        ll mid=(l+r)/2;
        if(mid*totalSum<=y){
            ans=mid;
            l=mid+1;
        } else{
            r=mid-1;
        }
    }
    return ans;
}

ll findMinInd(ll y){
    ll ans=-1;
    ll l=0,r=(ll)pre.size()-1;
    while(l<=r){
        ll mid=(l+r)/2;
        if(pre[mid].F>=y){
            ans=pre[mid].S;
            r=mid-1;
        } else{
            l=mid+1;
        }
    }
    return ans;
}

void solve(){
    cin>>n>>m;
    totalSum=0;
    rep(i,1,n+1) cin>>a[i], totalSum+=a[i];
    rep(i,1,m+1) cin>>x[i];
    pre.clear();
    pre.eb(0,0);
    ll currSum=0;
    rep(i,1,n+1){
        currSum+=a[i];
        if(currSum>pre.back().F){
            pre.eb(currSum,i);
        }
    }
    rep(i,1,m+1){
        ll y=findMaxIterations(x[i]);
        // sout("y:",y);
        ll sumLeft;
        if(y==inf){
            sumLeft=x[i];
        } else{
            sumLeft=x[i]-y*totalSum;
        }
        // sout("sumleft:",sumLeft);
        ll ind=findMinInd(sumLeft);
        if(ind==-1){
            cout<<-1<<" ";
        } else{
            cout<<n*y+ind-1<<" ";
        }
        // cout<<endl;
    }
    cout<<endl;
    
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    clock_t t1=clock();
    int t;
    cin>>t;
    // t=1;
    while(t--){
        solve();
    }
    cerr<<"Time elapsed: "<<(double)(clock()-t1)/1000<<" s"<<endl;
}


