#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), x(m);
  for (ll i = 0; i < n; i++) cin >> a[i];
  for (ll i = 0; i < m; i++) cin >> x[i];
  ll sum = 0, high = 0;
  for (ll i = 0; i < n; i++) {
    sum += a[i];
    if (sum > high) high = sum;
  }
  ll hdiff = high - sum;
  for (ll i = 0; i < m; i++) {
    ll revos = sum == 0 ? 0 : max((x[i] - 1 - hdiff) / sum, 0ll);
    ll currentSum = revos * sum + a[0], j = 0;
    for (; j < (n * 2) - 1; j++) {
      if (currentSum >= x[i]) break;
      currentSum += a[(j + 1) % n];
    }
    if (currentSum < x[i]) {
      cout << "-1"
           << " ";
      continue;
    }
    cout << revos * n + j << " ";
  }
  cout << endl;
}
int main() {
  ll t;
  cin >> t;
  while (t--) solve();
}
