#include <bits/stdc++.h>
using namespace std;
void solve(istream& cin, ostream& cout) {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  vector<long long> x(M);
  for (int i = 0; i < M; ++i) {
    cin >> x[i];
  }
  vector<long long> stIdx;
  vector<long long> stVal;
  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += a[i];
    if (sum > 0) {
      if (stVal.empty() || stVal.back() < sum) {
        stVal.push_back(sum);
        stIdx.push_back(i);
      }
    }
  }
  for (int ii = 0; ii < M; ++ii) {
    long long X = x[ii];
    long long answer = 0;
    if (stVal.empty() || (sum <= 0 && stVal.back() < X)) {
      answer = -1;
    } else {
      if (X <= stVal[0]) {
        answer = stIdx[0];
      } else if (X % stVal.back() == 0) {
        answer = N * (X / stVal.back()) - 1;
      } else {
        long long cycles = 0;
        if (X > stVal.back()) {
          cycles = (X / stVal.back());
          X -= (cycles * N);
          answer += (cycles * N);
        }
        int pos = lower_bound(stVal.begin(), stVal.end(), X) - stVal.begin();
        answer += stIdx[pos];
      }
    }
    cout << answer << " ";
  }
  cout << "\n";
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests;
  cin >> tests;
  while (tests > 0) {
    solve(cin, cout);
    tests -= 1;
  }
  return 0;
}
