#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long extend_gcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long d = extend_gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
long long modinv(long long a, long long p) { return power(a, p - 2, p); }
long long rowNum[] = {-1, 0, 0, 1};
long long colNum[] = {0, -1, 1, 0};
long long foo(long long mid, std::vector<long long> up, long long sum,
              long long x) {
  long long rem = x - sum * mid;
  if (rem <= 0) return 1;
  auto idx = lower_bound(up.begin(), up.end(), rem);
  if (idx != up.end())
    return 1;
  else
    return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    std::vector<long long> v(n), pref(n), up;
    std::vector<pair<long long, long long>> check;
    for (long long i = 0; i < n; i++) cin >> v[i];
    pref[0] = v[0];
    for (long long i = 1; i < n; i++) pref[i] = v[i] + pref[i - 1];
    long long temp = 0;
    check.push_back({0, 0});
    up.push_back(0);
    for (long long i = 0; i < n; i++) {
      if (pref[i] > check[check.size() - 1].first) {
        check.push_back({pref[i], i + 1});
        up.push_back(pref[i]);
      }
    }
    for (long long q = 0; q < m; q++) {
      long long x;
      cin >> x;
      long long l = 0, r = x + 100, ans = 0;
      while (l <= r) {
        long long mid = l + (r - l) / 2;
        if (foo(mid, up, pref[n - 1], x)) {
          r = mid - 1;
          ans = mid;
        } else {
          l = mid + 1;
        }
      }
      if (ans == -1) {
        cout << -1 << " ";
      } else {
        long long res = ans * n;
        long long rem = x - ans * pref[n - 1];
        auto idx = lower_bound(up.begin(), up.end(), rem) - up.begin();
        if (idx >= check.size())
          cout << "-1 ";
        else {
          res = res + check[idx].second;
          cout << res - 1 << " ";
        }
      }
    }
    cout << endl;
  }
}
