#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll inf = 1e17;
void solve() {
  int n, m;
  cin >> n >> m;
  vll a(n + 1), pref(n + 1);
  vpll prefix;
  ll MAX = -inf, sum;
  for (int i = 1; i <= (int)n; ++i) {
    cin >> a[i];
    pref[i] += pref[i - 1] + a[i];
    MAX = max(MAX, pref[i]);
  }
  sum = pref[n];
  for (int i = 1; i <= (int)n; ++i) {
    if (pref[i] < pref[i - 1]) continue;
    prefix.emplace_back(pref[i], i);
  };
  for (int i = 1; i <= (int)m; ++i) {
    ll x;
    cin >> x;
    if (MAX < x && sum <= 0) {
      cout << -1 << ' ';
      continue;
    }
    ll rounds = sum > 0 ? (x - MAX + sum - 1) / sum : 0;
    ll en = prefix.size() - 1, st = 0;
    x -= rounds * sum;
    ll ans = rounds * n, pos = -1;
    while (st <= en) {
      ll mid = st + (en - st) / 2;
      if (prefix[mid].first >= x) {
        pos = prefix[mid].second;
        en = mid - 1;
      } else {
        st = mid + 1;
      }
    }
    cout << ans + pos - 1 << ' ';
  }
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}
