#include <bits/stdc++.h>
using namespace std;
int t, n, m, x;
int findI(const vector<int64_t>& sum, int x) {
  int l = 1, r = n;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (sum[mid] < x)
      l = mid + 1;
    else
      r = mid;
  }
  return sum[l] >= x ? l : (sum[r] >= x ? r : -1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int64_t> sumIm(n + 1);
    int64_t lastSum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      int64_t sum = lastSum + x;
      sumIm[i] = max(sum, sumIm[i - 1]);
      lastSum = sum;
    }
    while (m--) {
      int64_t ans = 0;
      cin >> x;
      int especialI = findI(sumIm, x);
      if (especialI != -1) {
        cout << especialI - 1 << " ";
        continue;
      }
      int completes = lastSum > 0 ? (x - 1) / lastSum : 0;
      int toReach = x - completes * lastSum;
      ans = completes * n;
      int add = findI(sumIm, toReach);
      cout << (add == -1 ? -1 : ans + add - 1) << " ";
    }
    cout << "\n";
  }
  return 0;
}
