#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
inline long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long lowbit(long long x) { return (x & -x); }
inline long long kissme(long long x, long long y) {
  long long res = 1;
  if (x == 0) return 1;
  if (x == 1) return y;
  res = kissme(x / 2, y);
  res = res * res % mod;
  if (x % 2 == 1) res = res * y % mod;
  return res;
}
int T, n, m, a;
long long sum, mx;
vector<pair<long long, long long> > v, e;
long long calc(long long x) {
  if (v.back().second < x) return -1;
  long long res =
      lower_bound(v.begin(), v.end(), make_pair(x, 0ll)) - v.begin();
  return v[res].second;
}
void solve() {
  scanf("%d%d", &n, &m);
  v.clear();
  e.clear();
  mx = -1e15;
  sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    sum += a;
    v.push_back(make_pair(i, sum));
    mx = max(mx, sum);
  }
  sort(v.begin(), v.end());
  e.push_back(make_pair(v[0].second, v[0].first));
  for (int i = 1; i < v.size(); i++)
    if (v[i].second > e.back().second)
      e.push_back(make_pair(v[i].second, v[i].first));
  v = e;
  for (int i = 0; i < m; i++) {
    int x;
    long long ans = 0;
    scanf("%d", &x);
    if (sum <= 0) {
      printf("%lld ", calc(x));
      continue;
    }
    ans = max(1ll * (x - mx) / sum * n, 0ll);
    if ((x - mx) > 0 && x - (x - mx) / sum * sum > mx) ans += n;
    x -= ans / n * sum;
    ans += calc(x);
    printf("%lld ", ans);
  }
  printf("\n");
}
signed main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
