#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    map<long long, long long> rec;
    long long sum = 0, maxx = -10000000000;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      sum += x;
      if (sum > maxx) {
        maxx = sum;
        rec[sum] = i;
      }
    }
    for (long long i = 0; i < m; i++) {
      long long x;
      cin >> x;
      if (maxx >= x) {
        cout << rec.lower_bound(x)->second << " ";
      } else if (sum <= 0) {
        cout << -1 << " ";
      } else if ((x - maxx) % sum == 0) {
        x -= maxx;
        long long ans = n * (x / sum);
        long long r = rec.lower_bound(maxx)->second;
        cout << (ans + r) << " ";
      } else {
        long long ans = n * (x / sum);
        x %= sum;
        if (x == 0) {
          cout << (ans - 1) << " ";
          continue;
        }
        long long r = rec.lower_bound(x)->second;
        cout << (ans + r) << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
