import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

t = int(input())
from itertools import accumulate
import bisect
for _ in range(t):
    n,m = map(int, input().split())
    A = list(map(int, input().split()))
    X = list(map(int, input().split()))
    C = [0]+A
    C = list(accumulate(C))
    CM = [0]*(n+1)
    for i in range(1, n+1):
        CM[i] = max(CM[i-1], C[i])
    #print(C)
    #print(CM)
    p = C[-1]
    ans = [-1]*m
    for i, x in enumerate(X):
        j = bisect.bisect_left(CM, x)
        if j != n+1:
            ans[i] = j-1
        else:
            if p > 0:
                q, r = divmod(x, p)
                if r == 0:
                    ans[i] = n*q-1
                else:
                    j = bisect.bisect_left(CM, r)
                    if j != n+1:
                        ans[i] = n*q-1+j
            else:
                continue
    print(*ans)
