#include <bits/stdc++.h>
using namespace std;
inline long long min(long long x, long long y) { return x < y ? x : y; }
inline long long max(long long x, long long y) { return x > y ? x : y; }
inline void swap(long long &x, long long &y) {
  long long t = x;
  x = y;
  y = t;
  return;
}
namespace yspm {
inline long long read() {
  long long res = 0, f = 1;
  char k;
  while (!isdigit(k = getchar()))
    if (k == '-') f = -1;
  while (isdigit(k)) res = res * 10 + k - '0', k = getchar();
  return res * f;
}
const long long N = 2e5 + 10;
long long a[N], n, m, s[N];
map<long long, long long> mp;
signed main() {
  long long T = read();
  while (T--) {
    n = read();
    m = read();
    long long mx = -1e18;
    mp.clear();
    a[0] = read();
    mp[0] = 0;
    for (register long long i = 1; i < n; ++i) {
      a[i] = read(), s[i] = s[i - 1] + a[i];
      mx = max(s[i], mx);
      if (!mp.count(s[i])) mp[s[i]] = i;
    }
    a[n] = a[0];
    s[n] = s[n - 1] + a[n];
    mx = max(s[n], mx);
    if (!mp.count(s[n])) mp[s[n]] = n;
    map<long long, long long>::iterator it = mp.end();
    long long mn = 1e18;
    it--;
    while (1) {
      it->second = min(mn, it->second);
      mn = min(it->second, mn);
      if (it == mp.begin())
        break;
      else
        it--;
    }
    while (m--) {
      long long x = read() - a[0], ans = 0;
      if (s[n] <= 0 && mx < x) {
        printf("-1 ");
        continue;
      }
      if (x < 0) {
        printf("0 ");
        continue;
      }
      if (x > mx)
        ans += (x - mx + s[n] - 1) / s[n] * n,
            x -= (x - mx + s[n] - 1) / s[n] * s[n];
      assert(x <= mx);
      ans += mp.lower_bound(x)->second;
      printf("%lld ", ans);
    }
    puts("");
  }
  return 0;
}
}  // namespace yspm
signed main() { return yspm::main(); }
