#include <bits/stdc++.h>
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
using namespace std;
const int INF = INT_MAX;
const long long LNF = LONG_LONG_MAX;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n), x(m);
  for (int i = int(0); i < int(n); ++i) {
    cin >> a[i];
  }
  for (int i = int(0); i < int(m); ++i) {
    cin >> x[i];
  }
  vector<long long> pre(n + 1);
  for (int i = int(0); i < int(n); ++i) {
    pre[i + 1] = pre[i] + a[i];
  }
  vector<long long> preM(n + 1);
  for (int i = int(1); i < int(n + 1); ++i) {
    preM[i] = max(pre[i], preM[i - 1]);
  }
  long long sum = 0;
  vector<long long> ans(m, -1);
  for (int i = int(0); i < int(n); ++i) {
    sum += a[i];
  }
  for (int i = int(0); i < int(m); ++i) {
    long long cur = lower_bound(preM.begin(), preM.end(), x[i]) - preM.begin();
    if (cur != preM.size()) {
      ans[i] = cur - 1;
    }
  }
  if (sum > 0) {
    for (int i = int(0); i < int(m); ++i) {
      if (ans[i] != -1) continue;
      long long cur;
      if (sum == 1)
        cur = lower_bound(preM.begin(), preM.end(),
                          x[i] - ((x[i]) / sum - 1) * sum) -
              preM.begin();
      else
        cur =
            lower_bound(preM.begin(), preM.end(), x[i] - ((x[i]) / sum) * sum) -
            preM.begin();
      if (cur != preM.size()) {
        long long sub = max(0LL, ((x[i] - preM[n]) + sum - 1) / sum);
        if (sum == 1)
          ans[i] = (x[i] / sum - 1) * n - 1 + cur;
        else
          ans[i] = (x[i] / sum) * n - 1 + cur;
      }
    }
  }
  for (int i = 0; i < m; i++) cout << ans[i] << (i == m - 1 ? '\n' : ' ');
  ;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int tst = 1;
  cin >> tst;
  while (tst--) {
    solve();
  }
}
