#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[200200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long sum = 0;
    vector<pair<long long, int> > Pre;
    cin >> n >> m;
    long long last = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
      if (sum >= last) {
        Pre.push_back({sum, i});
        last = sum;
      }
    }
    while (m--) {
      long long x;
      cin >> x;
      auto B = [&](long long xx) {
        long long Ans = -1;
        long long L = 0, R = (int)Pre.size() - 1;
        while (L <= R) {
          if (Pre[((L + R) / 2)].first >= xx) {
            Ans = Pre[((L + R) / 2)].second;
            R = ((L + R) / 2) - 1;
          } else
            L = ((L + R) / 2) + 1;
        }
        return Ans;
      };
      long long b = B(x);
      if (b + 1) {
        cout << b << " ";
        continue;
      }
      if (sum <= 0) {
        cout << "-1 ";
        continue;
      }
      auto Big = [&](long long xx) {
        long long Ans = -1;
        long long L = 1, R = 1e9 + 7;
        while (L <= R) {
          if (sum * ((L + R) / 2) >= xx) {
            Ans = ((L + R) / 2) - 1;
            R = ((L + R) / 2) - 1;
          } else
            L = ((L + R) / 2) + 1;
        }
        assert(Ans != -1);
        return Ans;
      };
      long long ans = Big(x);
      long long c = B(x - ans * sum);
      ans *= n;
      ans += c;
      cout << ans << " ";
    }
    cout << endl;
  }
  return 0;
}
