#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e9 + 5;
long long int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> a(n), pref(n), c(n);
    vector<pair<long long int, long long int> > v(n);
    for (auto &x : a) {
      cin >> x;
    }
    for (long long int i = 0; i < n; i++) {
      pref[i] = a[i] + (i ? pref[i - 1] : 0);
      v[i] = {pref[i], i};
      c[i] = pref[i];
    }
    sort(c.begin(), c.end());
    sort(v.begin(), v.end());
    while (m--) {
      long long int x;
      cin >> x;
      long long int index = lower_bound(c.begin(), c.end(), x) - c.begin();
      if (index == n) {
        if (pref[n - 1] <= 0) {
          cout << -1 << " ";
          continue;
        }
        long long int p = (x - c[n - 1] + pref[n - 1] - 1) / pref[n - 1],
                      ans = p * n;
        x -= (pref[n - 1] * p);
        if (x <= 0) {
          cout << ans - 1 << " ";
          continue;
        }
        long long int index = lower_bound(c.begin(), c.end(), x) - c.begin();
        ans += v[index].second;
        cout << ans << " ";
      } else {
        cout << v[index].second << " ";
      }
    }
    cout << "\n";
  }
}
