#include <bits/stdc++.h>
using namespace std;
long long powermod(long long a, long long b, long long c) {
  long long ans = 1, tempans = a % c;
  while (b > 0) {
    if (b & 1 == 1) {
      ans = (ans * tempans) % c;
    }
    tempans = (tempans * tempans) % c;
    b = b >> 1;
  }
  return ans;
}
long long modinverse(long long a, long long m) { return powermod(a, m - 2, m); }
long long add(long long x, long long y) {
  x += y;
  if (x >= 1000000007) return x - 1000000007;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + 1000000007;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % 1000000007; }
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) cin >> a[i], sum += a[i];
  for (long long i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  map<long long, long long> index;
  vector<long long> v;
  long long ma = -1;
  for (long long i = 0; i < n; i++) {
    if (a[i] > ma) {
      ma = a[i];
      index[a[i]] = i;
      v.push_back(ma);
    }
  }
  while (m--) {
    long long x;
    cin >> x;
    auto it = lower_bound((v).begin(), (v).end(), x);
    if (it == v.end()) {
      if (sum > 0) {
        long long y = x / sum;
        x = (x % sum);
        auto it1 = lower_bound((v).begin(), (v).end(), x);
        if (it1 == v.end()) {
          cout << -1 << " ";
        } else {
          if (x == 0) {
            cout << y * n - 1 << endl;
          } else {
            long long ans = index[*it1] + y * n;
            cout << ans << " ";
          }
        }
      } else {
        cout << -1 << " ";
      }
    } else {
      cout << index[*it] << " ";
    }
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  long long count = 0;
  while (t--) {
    count++;
    solve();
  }
}
