import sys
from bisect import bisect_right

input = lambda: sys.stdin.readline().rstrip("\r\n")

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    d = {a[0]: 1}
    total = 0
    ck = [a[0]]
    for i, v in enumerate(a):
        total += v
        if total > ck[-1]:
            ck.append(total)
            d[total] = i + 1
    for i in b:
        if ck[-1]==0:
            print(-1,end=' ')
        elif ck[0] >= (i % ck[-1]) <= ck[-1]:
            ans = 0
            if i > ck[-1]:
                ans = (i // ck[-1]) * n
                i = i % ck[-1]
            if i != 0:
                j = bisect_right(ck, i) - 1
                ans += d[ck[j]]
            print(ans - 1, end=' ')
        else:
            print(-1, end=' ')
    print()
