#include <bits/stdc++.h>
using namespace std;
long long int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long binpow(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) result = (result * base);
    base = (base * base);
    power /= 2;
  }
  return result;
}
int main() {
  long long int t, cas = 1;
  cin >> t;
  while (t--) {
    long long int i, j, x, ans = 0, m, sum = 0, s = 0, n;
    cin >> n >> m;
    long long int a[n + 9];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    for (i = 0; i < m; i++) {
      bool flag = 0;
      ans = 99999999999999;
      cin >> x;
      long long int pos = 0, neg = 0, pans = 0, nans = 0;
      if (sum > 0 && x > 0) {
        pos = x % sum;
        neg = sum - pos;
        pans = (x / sum) * n;
        nans = (x / sum) * n + n;
      }
      if (sum < 0 && x < 0) {
        pos = x % sum;
        neg = sum - pos;
        pans = (x / sum) * n;
        nans = (x / sum) * n + n;
      }
      if (pos == 0 && pans - 1 != 0) ans = min(ans, pans - 1);
      long long int cnt = 0;
      for (j = 0; j < n; j++) {
        cnt += a[j];
        long long int k = x - cnt;
        if (k <= 0) {
          ans = min(ans, j);
        }
        if (cnt >= pos) {
          ans = min(ans, pans + j);
        }
        if (cnt >= neg) {
          ans = min(ans, nans + j);
        }
      }
      if (ans == 99999999999999)
        cout << -1 << " ";
      else
        cout << ans << " ";
    }
    cout << endl;
  }
}
