#include <bits/stdc++.h>
using namespace std;
long long my_bs(const vector<pair<long long, long long>> &pfx, long long x) {
  long long l = 0, r = pfx.size(), m;
  while (l <= r) {
    m = (l + r) / 2;
    if (pfx[m].first == x)
      return pfx[m].second;
    else if (pfx[m].first < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
void solve() {
  long long n, m, s = 0;
  cin >> n >> m;
  vector<long long> as(n);
  vector<pair<long long, long long>> pfx(n + 1);
  for (long long i = 0; i < n; ++i) {
    cin >> as[i];
    s += as[i];
    pfx[i + 1].first = pfx[i].first + as[i];
    pfx[i + 1].second = i;
  }
  sort(pfx.begin(), pfx.end());
  for (long long i = 0, x; i < m; ++i) {
    cin >> x;
    long long f = my_bs(pfx, x);
    if (pfx[n].first < x && pfx[n].first <= 0) {
      cout << -1 << " ";
    } else if (f != -1) {
      cout << f << " ";
    } else {
      long long full_cycles = x / max(1ll, s);
      long long sum_at_full_cycles = full_cycles * s;
      long long nf = my_bs(pfx, x - sum_at_full_cycles);
      if (nf == -1)
        cout << -1 << " ";
      else {
        if (x % s == 0) nf = -1;
        long long ans = full_cycles * n + nf;
        cout << ans << " ";
      }
    }
  }
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
