import sys
input = sys.stdin.readline
for _ in range(int(input())):
  N, M = map(int, input().split())
  a = list(map(int, input().split()))
  qs = list(map(int, input().split()))
  cs = [0] * (N + 1)
  t = [(0, 0)]
  for i in range(N):
    cs[i + 1] = cs[i] + a[i]
    t.append((cs[i + 1], i + 1))
  t.sort(key = lambda x: (x[0], x[1]))
  #print(t)
  res = [0] * M
  for i in range(M):
    q = qs[i]
    if cs[-1] > 0:
      if q - t[-1][0] >= 0: res[i] += -(-(q - t[-1][0]) // cs[-1]) * N
      q -= cs[-1] * -(-(q - t[-1][0]) // cs[-1])
    if cs[-1] <= 0 and t[-1][0] < q:
      res[i] = -1
      continue
    #print(q, res)
    ok = -1
    ng = N
    while ng - ok > 1:
      m = (ok + ng) // 2
      if t[m][0] < q: ok = m
      else: ng = m
    res[i] += t[ng][1] - 1
  print(*res)