T, = map(int, input().split())
for _ in range(T):
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    sx = sum(X)
    for i in range(1, N):
        X[i] += X[i-1]
    mx = max(X)
    Y = list(map(int, input().split()))
    L = [0]*M
    for i in range(M):
        y = Y[i]
        if sx > 0:
            k = -(-max(0, y-mx)//sx)
            nn = y-k*sx
        elif sx <= 0:
            k = 0
            if y <= mx:
                nn = y
            else:
                nn = -1
        L[i] = (i, k, nn)
    L.sort(lambda x:x[2])
    ans = [-1]*M
    j = 0
    for i in range(N):
        x = X[i]
        while j < M and x >= L[j][2]:
            l, k, _ = L[j]
            ans[l] = k*N + i
            j += 1
    print(*ans)


