#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.14159265358979323846;
template <typename T>
void read(vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) cin >> a[i];
}
template <typename T>
void print(vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) cout << a[i] << " ";
  cout << endl;
}
template <typename T>
void print2(vector<vector<T> >& a) {
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
template <typename T>
void read2(vector<vector<T> >& a) {
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      cin >> a[i][j];
    }
  }
}
void write() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  read(a);
  read(b);
  long long sum = 0;
  vector<long long> pf(n);
  set<long long> st;
  map<long long, int> mp;
  for (int i = 0; i < n; ++i) {
    pf[i] = a[i];
    if (i > 0) {
      pf[i] += pf[i - 1];
    }
  }
  st.insert(INF);
  for (int i = 0; i < n; ++i) {
    auto it = st.lower_bound(pf[i]);
    if (*it != INF && *it >= pf[i]) {
      mp[pf[i]] = min(i, mp[*it]);
    } else {
      mp[pf[i]] = i;
    }
    st.insert(pf[i]);
  }
  sum = pf[n - 1];
  for (int mm = 0; mm < m; ++mm) {
    long long x = b[mm];
    auto it = st.lower_bound(x);
    if (*it == INF) {
      if (sum <= 0) {
        cout << -1 << " ";
        continue;
      }
      long long res = (x / sum) * n;
      x = x % sum;
      auto it2 = st.lower_bound(x);
      if (x != 0) {
        res += mp[*it2];
      } else {
        res--;
      }
      cout << res << " ";
    } else {
      cout << mp[*it] << " ";
    }
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  for (int T = 0; T < t; ++T) write();
  return 0;
}
