#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> arr(n), ax(m);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ax[i];
  }
  vector<long long> dp(n + 1);
  dp[0] = 0;
  map<long long, long long> m1;
  long long mx = LONG_LONG_MIN;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = dp[i] + arr[i];
    mx = max(mx, dp[i + 1]);
    if (m1[mx] == 0) {
      m1[mx] = i + 1;
    }
  }
  for (int i = 0; i < m; i++) {
    if (dp[n] <= 0 && mx < ax[i]) {
      cout << "-1 ";
    } else {
      long long d = max(ax[i] - mx, 0ll);
      long long a1 = ceil((double)d / dp[n]);
      long long a2 = ax[i] - dp[n] * a1;
      map<long long, long long>::iterator ans = m1.lower_bound(a2);
      cout << (*ans).second + a1 * n - 1 << " ";
    }
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
