
# * need to implement here the concept of "pure" module
def pm(a, n):
    if n == 0:
        return a
    return a % n if a*n > 0 else a


for t in range(int(input())):
    n, m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    x = [int(x) for x in input().split()]

    sumarr = []
    sum = 0
    for i in a:
        sumarr.append((sum := sum + i))

    result = []
    for i in x:
        if x == 0:
            for j in range(len(sumarr)):
                if x == sumarr[j]:
                    result.append(j)
                    break
            else:
                result.append(-1)
        else:
            r = pm(i, sumarr[-1])

            if r == 0:
                result.append(int(i/sumarr[-1])*len(a)-1)
            else:
                for j in range(len(sumarr)):
                    if r == sumarr[j]:
                        b = (int(i/sumarr[-1]) if i*sumarr[-1] >
                             0 else 0) if sumarr[-1] != 0 else 0
                        result.append((b*len(a) if b else 0) + j)
                        break
                else:
                    result.append(-1)

    print(*result)
