#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int a[maxn];
pair<long long, int> sum[maxn];
long long rsum[maxn];
int f[maxn][30];
void init(int n) {
  for (int i = 1; i <= n; i++) f[i][0] = sum[i].second;
  for (int i = 1, imax = log2(n); i <= imax; i++)
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      if (rsum[f[j][i - 1]] < rsum[f[j + (1 << i - 1)][i - 1]])
        f[j][i] = f[j][i - 1];
      else if (rsum[f[j][i - 1]] > rsum[f[j + (1 << i - 1)][i - 1]])
        f[j][i] = f[j + (1 << i - 1)][i - 1];
      else
        f[j][i] = min(f[j][i - 1], f[j + (1 << i - 1)][i - 1]);
    }
}
int rmq(int l, int r) {
  int k = log2(r - l + 1);
  if (rsum[f[l][k]] < rsum[f[r - (1 << k) + 1][k]])
    return f[l][k];
  else if (rsum[f[l][k]] > rsum[f[r - (1 << k) + 1][k]])
    return f[r - (1 << k) + 1][k];
  return min(f[l][k], f[r - (1 << k) + 1][k]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, m, x;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      sum[i].first = sum[i - 1].first + a[i];
      sum[i].second = i;
      rsum[i] = sum[i].first;
    }
    long long base = sum[n].first;
    sort(sum + 1, sum + 1 + n);
    init(n);
    int ans(0), l(0), idx(0);
    for (int i = 1; i <= m; i++) {
      cin >> x;
      l = lower_bound(sum + 1, sum + 1 + n, pair<long long, int>(x, 0)) - sum;
      if (l > n) {
        if (base <= 0)
          cout << -1 << ' ';
        else {
          ans = x / base * n;
          x %= base;
          l = lower_bound(sum + 1, sum + 1 + n, pair<long long, int>(x, 0)) -
              sum;
          if (l > n)
            cout << -1 << ' ';
          else {
            if (x) {
              idx = rmq(l, n);
              cout << ans + idx - 1 << ' ';
            } else {
              cout << ans - 1 << ' ';
            }
          }
        }
        continue;
      }
      idx = rmq(l, n);
      cout << idx - 1 << ' ';
    }
    cout << '\n';
  }
  return 0;
}
