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]))

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

            ix = bisect_left(pre, mod)
            # print(ix, period, mod)
            ans.append(period * n - 1 + ix)
    else:
        lst, ans, ix = 0, [-1] * m, 0
        tem = sorted([(j, i) for i, j in enumerate(x)])

        for i in range(1, n + 1):
            lst = max(lst, cum[i])
            while ix < m and tem[ix][0] <= lst:
                ans[tem[ix][1]] = i - 1
                ix += 1

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