#include <bits/stdc++.h>
using namespace std;
vector<long long int> g, s, a;
bool f(long long int m, long long int x) {
  long long int sum = m * (a.back());
  long long int r = x - sum;
  if (r <= g.back()) {
    return true;
  }
  return false;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  a = vector<long long int>(n);
  long long int x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  g.clear();
  s.clear();
  if (a[0] > 0) {
    g.push_back(a[0]);
    s.push_back(0);
  }
  for (int i = 1; i < n; i++) {
    a[i] += a[i - 1];
    if (a[i] > 0) {
      if (g.empty() || a[i] > g.back()) {
        g.push_back(a[i]);
        s.push_back(i);
      }
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (!g.empty() and x <= g.back()) {
      long long int p = lower_bound(g.begin(), g.end(), x) - g.begin();
      cout << s[p] << " ";
    } else if (a[n - 1] <= 0) {
      cout << -1 << " ";
    } else {
      long long int p = x / a[n - 1];
      long long int r = x % a[n - 1];
      if (r > 0) {
        p++;
      }
      long long int l = 0, h = p, m;
      while (l < h) {
        m = (l + h) / 2;
        if (f(m, x)) {
          p = min(p, m);
          h = m - 1;
        } else {
          l = m + 1;
        }
      }
      long long int sum = p * a[n - 1];
      r = x - sum;
      long long int y = lower_bound(g.begin(), g.end(), r) - g.begin();
      long long int ans = p * n + s[y];
      cout << ans << " ";
    }
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
