#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m, x;
  cin >> n >> m;
  vector<long long> v(n), cs(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    if (i == 0)
      cs[i] = v[i];
    else
      cs[i] = cs[i - 1] + v[i];
  }
  vector<pair<long long, long long>> inc;
  for (int i = 0; i < n; ++i) {
    if (inc.size() == 0) {
      if (cs[i] > 0) inc.push_back({cs[i], i});
    } else {
      if (cs[i] > inc[inc.size() - 1].first) inc.push_back({cs[i], i});
    }
  }
  long long last = cs[n - 1], mx = -1;
  if (inc.size() > 0) mx = inc[inc.size() - 1].first;
  while (m--) {
    cin >> x;
    if (x <= v[0]) {
      cout << "0 ";
      continue;
    }
    if (last <= 0 && x > mx) {
      cout << "-1 ";
      continue;
    }
    long long ans = 0;
    if (x > mx) {
      ans = n * ((x - mx + last - 1) / last);
      x -= ((x - mx + last - 1) / last) * last;
    }
    if (x <= v[0]) {
      cout << ans << " ";
      continue;
    }
    int l = 0, r = inc[inc.size() - 1].first, mid;
    auto ok = [&](int y) {
      if (inc[y].first >= x) return true;
      return false;
    };
    int yes = -1;
    while (l <= r) {
      mid = l + (r - l) / 2;
      if (ok(mid)) {
        yes = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    ans += inc[yes].second;
    cout << ans << " ";
  }
  cout << endl;
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    solve();
  }
}
