
#include <bits/stdc++.h>  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
using namespace std;
typedef long long ll;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin>>t;
    while(t--){
        // cout<<"Case "<<t<<endl;
        ll n,m;
        cin>>n>>m;
        vector<ll> arr(n);
        for(ll i = 0;i<n;i++)
            cin>>arr[i];
        vector<ll> pre_sum(n);
        pre_sum[0] = arr[0];
        vector<ll> pre_max(n);
        pre_max[0] = arr[0];
        ll total_sum;
        ll mx = arr[0];
        ll cur_total = 0;
        for(ll i = 1;i<n;i++){
            pre_sum[i] = arr[i] + pre_sum[i-1];
            pre_max[i] = max(pre_max[i-1], pre_sum[i]);
        }
        mx = pre_max[n-1];
        total_sum = pre_sum[n-1];
        vector<ll> x(m);
        for(ll i =0;i<m;i++)
            cin>>x[i];
        for(ll i =0;i<m;i++){
            if(total_sum <= 0 && x[i] > mx){
                cout<<-1<<" ";
                continue;
            }
            if( x[i] <= mx){
                cout<< lower_bound(pre_max.begin(),pre_max.end(),x[i]) -pre_max.begin()<<" ";
                continue;
            }
            ll repeats = (x[i] - mx)%total_sum?(x[i] - mx)/total_sum+1:(x[i] - mx)/total_sum;
            ll ans = repeats*n + lower_bound(pre_max.begin(),pre_max.end(),x[i]-repeats*total_sum) -pre_max.begin();
            cout<< ans <<" ";
        }
        cout<<endl;
    }
    return 0;
}