#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
#define endl "\n"

typedef tree<ll, null_type, less<ll>, rb_tree_tag, 
             tree_order_statistics_node_update> ordered_set;
             
// find_by_order
// order_of_key 

const ll maxN=3e5+5;
ll n , m , k;

ll solve(ll x , map<ll,ll>& mp , ll sum){
    if(sum<=0)return 0;
    ll ps = (x/sum)*n ;
    ll ss = x - (x/sum)*sum ;
    auto it = mp.lower_bound(ss);
    if(it!=mp.end())ps+=it->s ;
    return ps;
}
void solve(){
    cin>> n >> m ;
    vector<ll> a(n) , x(m);
    ll sum=0;map<ll ,ll> mp ;
    for(ll i=0 ; i<n ; i++)cin>>a[i] , sum+=a[i];
    for(ll i=0 ; i<n ; i++){
        if(i!=0)a[i]+=a[i-1];
        mp[a[i]] = i+1 ;
    }mp[0]=0;
    for(ll i=0 ; i<m ; i++){
        cin>>x[i];
        ll ans = solve(x[i] , mp , sum);
        cout<<ans-1<<" ";
    }cout<<endl;
    
}

int main(){
	fast;
	ll t =1 ;
	cin>> t ; 
	while(t--)solve();
}
