   #include<bits/stdc++.h>
   using namespace std;
   #define gc getchar_unlocked
   #define ll long long
   #define PI 3.1415926535897932384626
   #define fo(i,n) for(i=0;i<n;i++)
   #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
   #define pb push_back
   #define mp make_pair
   #define xx first
   #define yy second
   #define all(x) x.begin(), x.end()
   #define rall(x) x.rbegin(), x.rend()
   #define clr(x) memset(x, 0, sizeof(x))
   #define sortall(x) sort(all(x))
   #define ar array
   #define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
   #define rtr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+)
   typedef pair<int, int> pi;
   typedef pair<ll, ll> pl;
   typedef vector<int> vi;
   typedef vector<ll> vl;
   typedef vector<pi> vpi;
   typedef vector<pl> vpl;
   typedef vector<vi> vvi;
   typedef vector<vl> vvl;

   const int M = 1000000007;
   const int N = 1e6;



   /* ==========  私のクソコード ========= */

   void solve() {
    ll n,m;
    cin>>n>>m;
    ll arr[n];
    ll sum=0;
    ll mx=-M;
    for(ll i=0;i<n;i++)cin>>arr[i],sum+=arr[i],mx=max(mx,sum);
    vector<ar<ll,2>> q;
    ll ans[m]={};
    for(ll i=0;i<m;i++){
        ll x;
        cin>>x;
        if(x>mx && sum<=0){
            ans[i]=-1;
        }
        else{
            if(sum>0){ll k=(x-mx+sum-1)/sum;
            ans[i]+=k*n;
            q.pb({x-k*sum,i});}
            else q.pb({x,i});
        }
    }
    sum=0;
    int j=0;
    int k=q.size();
    sort(all(q));
    for(int i=0;i<n;i++){
        sum+=arr[i];
        while(j<k && q[j][0]<=sum){
            ans[q[j][1]]+=(i);
            j++;
        }
    }
    for(int i=0;i<m;i++)cout<<ans[i]<<" ";
    cout<<"\n";



   }

   int main() {
       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
       int PP = 1;
       cin>>PP;
       while(PP--) {
           solve();
       }
       return 0;
   }

   // ====================== 私は偉大だ ========================= //
