#include <bits/stdc++.h>
using namespace std;
const bool debug = 0;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<pair<long long int, int> > d(m);
  for (int &x : a) cin >> x;
  for (int i = 0; i < m; ++i) {
    cin >> d[i].first;
    d[i].second = i;
  }
  sort(d.begin(), d.end());
  vector<long long int> pref(n), mxm(n);
  mxm[0] = pref[0] = a[0];
  for (int i = 1; i < n; ++i) {
    pref[i] = pref[i - 1] + a[i];
    mxm[i] = max(pref[i], mxm[i - 1]);
  }
  int l = 0;
  vector<long long int> ans(m);
  for (int i = 0; i < n; ++i) {
    while (l < m && d[l].first <= pref[i]) {
      ans[d[l++].second] = i;
    }
  }
  if (pref[n - 1] <= 0) {
    while (l < m) ans[d[l++].second] = -1;
  } else {
    while (l < m) {
      long long int lo = 0, hi = 1000000007;
      while (lo < hi) {
        long long int mid = lo + (1 - lo + hi) / 2;
        if (mid * pref[n - 1] < d[l].first)
          lo = mid;
        else
          hi = mid - 1;
      }
      ans[d[l].second] = (n)*lo;
      d[l].first -= pref[n - 1] * lo;
      int pos = lower_bound(mxm.begin(), mxm.end(), d[l].first) - mxm.begin();
      ans[d[l++].second] += pos;
    }
  }
  for (int i = 0; i < m; ++i) cout << ans[i] << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int _;
  cin >> _;
  while (_--) {
    solve();
  }
  return 0;
}
