#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int ddx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int ddy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, d, i, j, k, l, m, n, sum = 0, temp = 0, f = 0, cnt = 0;
    cin >> n >> m;
    long long arr[n];
    for (i = 0; i < n; i++) cin >> arr[i];
    long long pre[n];
    pre[0] = arr[0];
    for (i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];
    set<int> st;
    map<int, int> mp;
    for (i = 0; i < n; i++)
      if (mp[pre[i]] == 0) mp[pre[i]] = i + 1;
    for (i = 0; i < n; i++) {
      if (i == 0) {
        if (pre[i] > 0) st.insert(pre[i]);
      } else if (pre[i] > pre[i - 1])
        st.insert(pre[i]);
    }
    for (i = n - 2; i >= 0; i--) {
      if (pre[i] == pre[n - 1]) cnt++;
    }
    while (m--) {
      cin >> k;
      if (pre[n - 1] <= 0) {
        cout << -1 << " ";
        continue;
      }
      long long quo = (k / pre[n - 1]);
      long long rem = k - quo * pre[n - 1];
      int req = *st.upper_bound(rem - 1);
      long long ans = 0;
      if (quo > 0) ans += quo * n - 1;
      if (rem == 0) ans -= cnt;
      if (rem > 0) ans += mp[req] - 1 + (quo > 0);
      cout << ans << " ";
    }
    cout << "\n";
  }
}
