#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const long long INFLL = (long long)INF * (long long)INF;
const long double EPS = 10e-9;
const unsigned int M = 1000000007;
long double pi = 2 * acos(0.0);
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, long long> > available;
  long long pref[n];
  pref[0] = a[0];
  available.push_back(make_pair(a[0], 0));
  for (long long i = 1; i < n; ++i) {
    pref[i] = pref[i - 1] + a[i];
    available.push_back(make_pair(pref[i], i));
  }
  sort(available.begin(), available.end());
  long long id = available[n - 1].second;
  while (m--) {
    long long x;
    cin >> x;
    auto index =
        lower_bound(available.begin(), available.end(), make_pair(x, -1ll)) -
        available.begin();
    if (x == pref[0])
      cout << 0 << " ";
    else if (index < n) {
      cout << available[index].second << " ";
    } else if (pref[n - 1] <= 0)
      cout << -1 << " ";
    else {
      long long temp = x;
      long long ans = 0;
      long long temp2 = (temp + pref[n - 1] - 1) / pref[n - 1];
      ans += ((n) * (temp2 - 1));
      x -= pref[n - 1] * (temp2 - 1);
      auto index =
          lower_bound(available.begin(), available.end(), make_pair(x, -1ll)) -
          available.begin();
      ans += available[index].second;
      cout << ans << " ";
    }
  }
  cout << endl;
}
int32_t main() {
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
