#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
const ll INF = 4e18;
void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
  cout << fixed << setprecision(15) << head;
  print0(tail...);
}
void print() { print0("\n"); }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
  print0(head);
  if (sizeof...(Tail) > 0) print0(" ");
  print(tail...);
}
template <class T>
class bsegment_tree {
 public:
  ll size;
  vector<T> data;
  T default_value;
  bsegment_tree(ll n) {
    default_value = get_default_value();
    ll siz = 1;
    while (siz < n) {
      siz = siz * 2;
    }
    data.resize(siz * 2, default_value);
    size = siz;
  }
  ~bsegment_tree() {}
  T compare(T& a, T& b) { return min(a, b); }
  T get_default_value() { return -1; }
  void update(ll k, T value) {
    k += size - 1;
    data[k] = value;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = compare(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
  T query_open(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) {
      return default_value;
    }
    if (a <= l && r <= b) {
      return data[k];
    }
    T vl = query_open(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query_open(a, b, k * 2 + 2, (l + r) / 2, r);
    return compare(vl, vr);
  }
  T query(ll a, ll b) { return query_open(a, b + 1, 0, 0, size); }
};
using segment_tree = bsegment_tree<ll>;
void output(vector<ll>& answer) {
  ll m = answer.size();
  for (ll i = 0; i < m; i++) {
    if (i > 0) putchar(' ');
    cout << answer[i];
  }
  cout << endl;
}
void solve() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<ll> x(m);
  for (ll i = 0; i < m; i++) {
    cin >> x[i];
  }
  vector<pll> cum(n);
  ll mxcum = -INF;
  for (ll i = 0; i < n; i++) {
    ll c = a[i] + (i == 0 ? 0LL : cum[i - 1].first);
    cum[i] = {c, i};
    mxcum = max(mxcum, cum[i].first);
  }
  ll loop = cum[n - 1].first;
  sort(cum.begin(), cum.end());
  auto seg = segment_tree(n);
  for (ll i = 0; i < n; i++) {
    seg.update(i, cum[i].second);
  }
  vector<ll> answer;
  if (loop > 0) {
    for (ll i = 0; i < m; i++) {
      ll k = 0;
      if (x[i] > mxcum) {
        k = -1 + (x[i] - mxcum) / loop;
        while (x[i] > k * loop + mxcum) {
          k++;
        }
      }
      ll y = x[i] - k * loop;
      ll ind = lower_bound(cum.begin(), cum.end(), pll({y, -1})) - cum.begin();
      ll ans = k * loop + seg.query(ind, n - 1);
      answer.push_back(ans);
    }
  } else {
    for (ll i = 0; i < m; i++) {
      ll y = x[i];
      ll ind = lower_bound(cum.begin(), cum.end(), pll({y, -1})) - cum.begin();
      ll ans = seg.query(ind, n - 1);
      answer.push_back(ans);
    }
  }
  output(answer);
}
int main() {
  ll t;
  cin >> t;
  for (ll i = 0; i < t; i++) {
    solve();
  }
}
