#include <bits/stdc++.h>
using namespace std;
void solve(int _t) {
  int n, m;
  cin >> n >> m;
  int arr[n], query[m];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < m; i++) cin >> query[i];
  long long cyclePeak = arr[0];
  long long cycleSum = 0;
  map<long long, int> presum;
  for (int i = 0; i < n; i++) {
    cycleSum += arr[i];
    cyclePeak = max(cyclePeak, cycleSum);
    if (presum.find(cycleSum) == presum.end()) presum[cycleSum] = i;
  }
  for (int i = 0; i < m; i++) {
    long long t = query[i];
    if (cyclePeak < t && cycleSum <= 0) {
      cout << "-1 ";
    } else {
      long long ans = 0;
      long long cycles = (cycleSum <= 0 || t <= cyclePeak)
                             ? 0
                             : ceil((double)(t - cyclePeak) / cycleSum);
      ans += cycles * n;
      t -= cycles * cycleSum;
      auto it = presum.lower_bound(t);
      ans += (*it).second;
      cout << ans << " ";
    }
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) solve(t);
}
