#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 123456;
const long long INF = 2e18;
template <class T>
inline void chmax(T &x, T y) {
  x = max((x), (y));
}
template <class T>
inline void chmin(T &x, T y) {
  x = min((x), (y));
}
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void usmlloan() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> a(n), pre(n);
  vector<int64_t> pre_max(n);
  int64_t mx = -INF;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    pre[i] = a[i];
    if (i > 0) pre[i] += pre[i - 1];
    pre_max[i] = pre[i];
    if (i > 0) chmax(pre_max[i], pre_max[i - 1]);
    chmax(mx, pre[i]);
  }
  int64_t sum = pre[n - 1];
  while (m--) {
    int64_t x;
    cin >> x;
    if (x > mx and sum <= 0) {
      cout << -1 << " ";
      continue;
    }
    int64_t l = 0, r = 2e9, mid;
    int64_t use = -1;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (mid * sum + mx >= x) {
        use = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    if (use * sum >= x) {
      cout << use * n - 1 << " ";
      continue;
    }
    l = 0, r = n - 1;
    int64_t use2 = -1;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (use * sum + pre_max[mid] >= x) {
        use2 = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    cout << use * n - 1 + use2 + 1 << " ";
  }
  cout << "\n";
}
int32_t main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  while (n--) {
    usmlloan();
  }
}
