#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    vector<int> Q(M);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> Q[i];
    vector<int> prefixSums(N);
    prefixSums[0] = A[0];
    for (int i = 1; i < N; i++) prefixSums[i] = prefixSums[i - 1] + A[i];
    int totalSum = prefixSums[N - 1];
    for (int q = 0; q < M; q++) {
      if (totalSum == 0) {
        bool found = false;
        for (int i = 0; i < prefixSums.size(); i++) {
          if (prefixSums[i] >= Q[q]) {
            cout << i << ' ';
            found = true;
            break;
          }
        }
        if (!found) cout << -1 << ' ';
      } else {
        bool found = false;
        long long minFound = 1e18;
        for (int i = 0; i < prefixSums.size(); i++) {
          if (prefixSums[i] >= Q[q]) {
            minFound = i;
            found = true;
            break;
          }
          if ((Q[q] - prefixSums[i]) % totalSum == 0) {
            long long cycles = abs(Q[q] - prefixSums[i]) / abs(totalSum);
            if (prefixSums[i] + cycles * totalSum >= Q[q]) {
              minFound = min(minFound, cycles * N + i);
              found = true;
            }
          }
        }
        if (!found)
          cout << -1 << ' ';
        else
          cout << minFound << ' ';
      }
    }
    cout << endl;
  }
  return 0;
}
