#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long x;
  vector<long long> v;
  vector<long long> prefix;
  vector<long long> pre;
  long long mx = 0;
  long long sum = 0;
  map<int, int> make_pair, mp1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    sum += x;
    if (!make_pair.count(sum) && x > 0) {
      make_pair[sum] = i;
    }
    if (i != 0 && !mp1.count(sum) && x > 0) {
      mp1[sum] = i;
    }
    if (x > 0) {
      prefix.push_back(sum);
      if (i != 0) {
        pre.push_back(sum);
      }
    }
    mx = max(mx, sum);
  }
  sort(prefix.begin(), prefix.end());
  sort(pre.begin(), pre.end());
  vector<long long> arr;
  for (int i = 0; i < m; i++) {
    cin >> x;
    arr.push_back(x);
  }
  vector<long long> ans;
  for (int i = 0; i < m; i++) {
    x = arr[i] - v[0];
    long long ct = 0;
    if (mx == 0) {
      ans.push_back(-1);
      continue;
    }
    if (x <= 0) {
      ans.push_back(0);
      continue;
    }
    if (x > mx) {
      long long z = x - mx;
      if (sum <= 0) {
        ct = -1;
        ans.push_back(-1);
        continue;
      }
      long long ans1 = (z / sum);
      if (z % sum != 0) {
        ans1++;
      }
      ct = ans1 * n;
      if (v[0] == 0) {
        ct--;
      }
      long long val = x - sum * ans1;
      vector<long long>::iterator it =
          lower_bound(prefix.begin(), prefix.end(), val);
      long long ind = make_pair[*it];
      ct += (ind + 1);
    } else {
      vector<long long>::iterator it = lower_bound(pre.begin(), pre.end(), x);
      if (it == pre.end()) {
        ct = n;
      } else {
        long long ind = mp1[*it];
        ct = ind;
      }
    }
    ans.push_back(ct);
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
