t=int(input())
for i in range(t):
    s=input().split(" ")
    n=int(s[0])
    m=int(s[1])
    a=input().split(" ")
    l=[int(a[0])]
    for j in range(1,n):
        l.append(l[-1]+int(a[j]))
    x=input().split(" ")
    for j in range(m):
        b=int(x[j])
        for k in range(n):
            if l[k]==b:
                print(k,end=" ")
                break
        if l[k]!=b:
            if l[-1]==0:
                print(-1,end=" ")
            else:
                p=0
                mi=0
                for k in range(n):
                    c=b-l[k]
                    d=c//l[-1]
                    if d>0 and c%l[-1]==0:
                        if p==0:
                            mi=d*n+k
                            p=-1
                        else:
                            mi=min(d*n+k,mi)
                if mi==0:
                    print(-1,end=" ")
                else:
                    print(mi,end=" ")
    print()
