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])
                b+=c
                n1+=1
                c=0
    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:
                l=n1/2
                h=round(l)
                while round(l)>0:
                    if e[h][0]<x[i]:
                        h=min(n1-1,h+round(l/2))
                    else:
                        h=max(0,h-round(l/2))
                    l/=2
                h-=1
                while h>=0 and e[h][0]==e[h+1][0]:
                    h-=1
                while e[h][0]<x[i]:
                    h+=1
                y.append(e[h][1])
            elif f>0:
                x1=(x[i]-g)//f
                if (x[i]-g)%f!=0:
                    x1+=1
                x[i]-=x1*f
                l=n1/2
                h=round(l)
                while round(l)>0:
                    if e[h][0]<x[i]:
                        h=min(n1-1,h+round(l/2))
                    else:
                        h=max(0,h-round(l/2))
                    l/=2
                h-=1
                while h>=0 and e[h][0]==e[h+1][0]:
                    h-=1
                while e[h][0]<x[i] and h<n-1:
                    h+=1
                y.append(e[h][1]+n*x1)
            else:
                y.append(-1)
    print(*y)  