#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
using namespace std;
using LL = long long;
constexpr LL mod = 1e9 + 7;
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long ret = ex_gcd(b, a % b, y, x);
  y -= a / b * x;
  return ret;
}
LL mul(LL u, LL v, LL p) {
  return (u * v - LL((long double)u * v / p) * p + p) % p;
}
LL bin(LL x, LL n, LL MOD) {
  LL ret = MOD != 1;
  for (x %= MOD; n; n >>= 1, x = x * x % MOD)
    if (n & 1) ret = ret * x % MOD;
  return ret;
}
LL norm(LL x) { return x >= mod ? (x - mod) : x; }
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
inline long long get_inv(long long a) {
  long long x, y;
  ex_gcd(a, mod, x, y);
  return norm(x + mod);
}
template <class T>
inline void umin(T &x, T y) {
  x = x > y ? y : x;
}
template <class T>
inline void umax(T &x, T y) {
  x = x < y ? y : x;
}
template <class T>
inline void dec(T &x, T y) {
  x -= y;
  if (x < 0) x += mod;
}
template <class T>
inline void add(T &x, T y) {
  x += y;
  if (x >= mod) x -= mod;
}
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename... Args>
void read(T &first, Args &...args) {
  read(first);
  read(args...);
}
template <class T>
LL ctz(T a) {
  return sizeof(T) > 2 ? __builtin_ctzll(a) : __builtin_ctz(a);
}
template <class T>
inline T gcd(T _a, T _b) {
  T a = abs(_a), b = abs(_b);
  LL shift = ctz(a | b);
  for (b >>= ctz(b), a >>= ctz(a); a; a -= b, a >>= ctz(a))
    if (a < b) swap(a, b);
  return b << shift;
}
const double PI = acos(-1.0);
constexpr LL INF = 0x3f3f3f3f;
constexpr long long linf = 0x3f3f3f3f3f3f3f3f;
constexpr unsigned long long base = 2333, P_1 = 19260817, P_2 = 999998639;
constexpr LL maxn = 1e6 + 10;
int32_t main() {
  std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cout << fixed << setprecision(10);
  LL x, n, m;
  LL ___T;
  cin >> ___T;
  for (LL __CS = 1; __CS <= ___T; __CS++) {
    cin >> n >> m;
    LL sum = 0;
    vector<pair<LL, LL> > v;
    for (LL i = 0; i < n; i++) {
      cin >> x;
      sum += x;
      if (not i or sum > v.back().first) {
        v.emplace_back(sum, i);
      }
    }
    for (LL i = 0; i < m; i++) {
      LL x;
      cin >> x;
      if (sum <= 0) {
        if (x > v.back().first) {
          cout << "-1 ";
        } else {
          cout << lower_bound((v).begin(), (v).end(), make_pair(x, 0ll))->second
               << " ";
        }
      } else {
        LL r = max(0ll, (x - v.back().first + sum - 1) / sum);
        cout << r * m + lower_bound((v).begin(), (v).end(),
                                    make_pair(x - r * sum, 0ll))
                            ->second
             << " ";
      }
    }
    cout << '\12';
  }
  return 0;
}
