#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, b, c, d, e, i, j, k, l, n, m, x, y, t, p, mx, sm;
  cin >> t;
  for (p = 1; p <= t; p++) {
    vec.clear();
    cin >> n >> m;
    mx = -1e18;
    sm = 0;
    for (i = 1; i <= n; i++) {
      cin >> a;
      sm += a;
      vec.push_back({sm, i});
      mx = max(mx, sm);
    }
    sort(vec.begin(), vec.end());
    pair<long long int, long long int> pp;
    for (i = 0; i < m; i++) {
      cin >> a;
      if (a <= mx) {
        pp = {a, 0};
        b = lower_bound(vec.begin(), vec.end(), pp) - vec.begin();
        cout << vec[b].second - 1 << " ";
      } else {
        if (sm <= 0) {
          cout << -1 << " ";
        } else {
          c = a - mx;
          x = 0;
          x += (c / sm);
          if (c % sm) {
            x++;
          }
          c = a - (x * sm);
          x = x * n;
          if (c > 0) {
            pp = {c, 0};
            b = lower_bound(vec.begin(), vec.end(), pp) - vec.begin();
            x += vec[b].second;
          }
          x--;
          cout << x << " ";
        }
      }
    }
    cout << endl;
  }
}
