#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return {i, j};
}
struct printer {
  ~printer() { cerr << endl; }
  template <class c>
  printer& operator,(c x) {
    cerr << boolalpha << x;
    return *this;
  }
  printer& operator,(string x) {
    cerr << x;
    return *this;
  }
  template <class c, class d>
  printer& operator,(pair<c, d> x) {
    return *this, "(", x.first, ", ", x.second, ")";
  }
  template <class... d, template <class...> class c>
  printer& operator,(c<d...> x) {
    return *this, range(begin(x), end(x));
  }
  template <class c>
  printer& operator,(rge<c> x) {
    *this, "[";
    for (auto it = x.b; it != x.e; ++it) *this, (it == x.b ? "" : ", "), *it;
    return *this, "]";
  }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
long long cum[20005], ans[20005], mx[20005];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    cum[i] = cum[i - 1] + a;
  }
  mx[0] = -1e18;
  for (int i = 1; i <= n; i++) {
    mx[i] = max(mx[i - 1], cum[i]);
  }
  for (int i = 1; i <= m; i++) {
    long long ar;
    cin >> ar;
    if (cum[n] <= 0 && mx[n] <= ar)
      ans[i] = -1;
    else {
      long long lo = 0, hi = 1e9;
      while (hi > lo) {
        long long mid = (lo + hi + 1) / 2;
        if (mid < 1e18 / cum[n] && mid * cum[n] <= ar && mx[n] <= ar)
          lo = mid;
        else
          hi = mid - 1;
      }
      long long total = max(0ll, n * lo - 1);
      ar -= lo * cum[n];
      if (ar > 0 && ar >= cum[1]) {
        lo = 1, hi = n;
        while (hi > lo) {
          long long mid = (lo + hi) / 2;
          if (mx[mid] <= ar)
            hi = mid;
          else
            hi = mid - 1;
        }
        total += total == 0 ? hi - 1 : hi;
      }
      ans[i] = total;
      cout << ans[i] << endl;
    }
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
