#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long tot = 0;
    long long a[n];
    vector<pair<long long, int>> v;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      tot = tot + a[i];
      v.push_back({tot, i});
    }
    sort(v.begin(), v.end());
    long long x;
    long long pre = 0;
    for (int i = 0; i < m; i++) {
      pre = a[0];
      cin >> x;
      if (x <= pre) {
        cout << 0 << " ";
      } else if (x <= v[n - 1].first) {
        pre = x;
        int st = 0;
        int en = n - 1;
        long long ans = 0;
        while (st <= en) {
          int mid = (st + en) / 2;
          if (v[mid].first >= pre) {
            ans = v[mid].second;
            en = mid - 1;
          } else {
            st = mid + 1;
          }
        }
        cout << ans << " ";
      } else if (tot > 0) {
        long long roun = (x - v[n - 1].first) / tot;
        roun = roun - 5;
        roun = max((long long)0, roun);
        while (((roun + 2) * tot) + v[n - 1].first < x) {
          roun++;
        }
        if (v[n - 1].first + ((roun + 1) * tot) < x) {
          roun++;
        }
        if (v[n - 1].first + ((roun + 1) * tot) < x) {
          roun++;
        }
        if (v[n - 1].first + ((roun)*tot) < x) {
          roun++;
        }
        pre = x - (roun * tot);
        int st = 0;
        int en = n - 1;
        long long ans = 0;
        while (st <= en) {
          int mid = (st + en) / 2;
          if (v[mid].first >= pre) {
            ans = v[mid].second;
            en = mid - 1;
          } else {
            st = mid + 1;
          }
        }
        ans = ans + (roun * n);
        cout << ans << " ";
      } else {
        cout << -1 << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
