#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> a(n), psum(n);
    vector<long long> pp, pi;
    for (long long i = (0); i < (n); i++) cin >> a[i];
    psum[0] = a[0];
    pp.push_back(psum[0]);
    pi.push_back(0);
    long long lastpsum = -1;
    for (long long i = (1); i < (n); i++) {
      psum[i] = a[i] + psum[i - 1];
      if (psum[i] > psum[i - 1]) pp.push_back(psum[i]), pi.push_back(i);
    }
    lastpsum = psum[n - 1];
    sort((psum).begin(), (psum).end());
    long long maxpsum = psum[n - 1];
    while (m--) {
      long long x;
      cin >> x;
      if (maxpsum < x && lastpsum <= 0) {
        cout << "-1 ";
        continue;
      }
      long long ans = 0;
      if (x > maxpsum) {
        ans += ((x - maxpsum + lastpsum - 1) / lastpsum);
        x -= ans * lastpsum;
      }
      long long ind = lower_bound((pp).begin(), (pp).end(), x) - pp.begin();
      if (ind >= 0 && ind < pi.size())
        cout << (ans * n) + pi[ind] << " ";
      else
        cout << (ans * n) << " ";
    }
    cout << "\n";
  }
  return 0;
}
