for k in range(int(input())):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    x=list(map(int,input().split()))
    b=0
    c=0
    d=0
    e=[]
    y=[]
    n1=0
    for i in range(n):
        if d==0:
            if a[i]>0:
                b+=a[i]
                e.append([b,i])
                n1+=1
            else:
                d=1
                c=a[i]
        else:
            c+=a[i]
            if c>0:
                d=0
                e.append([b+c,i])
                n1+=1
    f=b+c
    if e==[]:
        y=[-1 for i in range(m)]
    else:
        g=e[-1][0]
        for i in range(m):
            if x[i]<=g:
                for j in range(n1):
                    if e[j][0]>=x[i]:
                        y.append(e[j][1])
                        break
            elif f>0:
                x1=x[i]//f
                if x[i]%f==0:
                    y.append(n*x1-1)
                else:
                    x[i]%=f
                    for j in range(n1):
                        if e[j][0]>=x[i]:
                            y.append(e[j][1]+n*x1)
                            break
            else:
                y.append(-1)
    print(*y)