#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long T, n, m, maxn, l, r, mid, cnt, cnt2, ans;
long long a[N], x[N], sum[N], sum2[N], s[N];
signed main() {
  cin >> T;
  while (T--) {
    cnt = 0;
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i];
    for (long long i = 1; i <= m; i++) cin >> x[i];
    maxn = sum[1];
    for (long long i = 2; i <= n; i++) maxn = max(maxn, sum[i]);
    for (long long i = 1; i <= n; i++) {
      if (sum2[cnt] < sum[i] || i == 1) {
        sum2[++cnt] = sum[i];
        s[cnt] = i;
      }
    }
    for (long long i = 1; i <= m; i++) {
      if (maxn < x[i] && sum[n] <= 0) {
        cout << -1 << " ";
        continue;
      }
      if (maxn >= x[i])
        cnt2 = 0;
      else {
        cnt2 = (x[i] - maxn + 1) / sum[n];
      }
      if (cnt2 * sum[n] == x[i]) {
        cout << cnt2 * n - 1 << " ";
        continue;
      }
      l = 1;
      r = cnt;
      while (l <= r) {
        mid = (l + r) / 2;
        if (sum2[mid] >= x[i] - cnt2 * sum[n])
          ans = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      cout << cnt2 * n + s[ans] - 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
