def find():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    x = list(map(int, input().split()))
    sum_a = sum(a)
    res = [-1] * m
    s = 0
    for j in range(n):
        s += a[j]
        for k in range(m):
            if x[k] == s:
                res[k] = min(j, res[k]) if res[k] != -1 else j
            elif sum_a > 0 == (x[k] - s) % sum_a:
                if res[k] == -1:
                    res[k] = (x[k] - s) // sum_a * n + j
                else:
                    res[k] = min(res[k], (x[k] - s) // sum_a * n + j)
    return res


for i in range(int(input())):
    print(*find())