from __future__ import division
from sys import stdin, stdout
from bisect import *
from collections import *

rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda: int(stdin.readline())
rints = lambda: [int(x) for x in stdin.readline().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
ceil1, out = lambda a, b: (a + b - 1) // b, []

for _ in range(int(input())):
    n, m = rints()
    a, x = rints(), rints()
    cum, ans = [0], []
    for i in range(n):
        cum.append(cum[-1] + a[i])

    pre = [0]
    for i in range(1, n + 1):
        pre.append(max(pre[-1], cum[i]))

    ma = max(cum)
    for i in x:
        period = ceil1((i - ma), cum[-1])
        mod = cum[-1] - (i - ma) % cum[-1]
        if mod == cum[-1]:
            mod = 0
        mod = max(1, ma - mod)
        if i <= ma:
            period, mod = 0, i

        if period and cum[-1] <= 0:
            ans.append(-1)
        else:
            ix = bisect_left(pre, mod)
        ans.append(period * n - 1 + ix)

    out.append(' '.join(map(str, ans)))
pr(out, '\n')
