from collections import defaultdict 
for _ in range(int(input())):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    q=list(map(int,input().split()))
    d=defaultdict(list)
    d1=defaultdict(list)
    ans1=[]
    for i in range(n):
        d[l[i]].append(i)
    s=set()
    b=sum(l)
    c=0
    if b!=0: 
        print(d)
        for i in range(n):
            c+=l[i]
            s.add(c%b)
            d[l[i]].append(c)
            d1[c%b].append([c,i])
        print(d,d1,s)
        for inp in q:
            c1=inp%b
            if c1 in s:
                s2=d1[c1].index(max(d1[c1]))
                #print("c1,s2= ",c1,s2)
                sum1=d1[c1][s2][0]
                ans=d1[c1][s2][1]
                gg=(inp-sum1)//b
                ans+=n*gg
                if ans<0:
                    ans=-1
                ans1.append(ans)
                #print(ans,end=" ")
                #print(sum1,gg)
            else:
                ans1.append(-1)
        print(*ans1)
    else:
        s=set(l)
        for inp in q:
            if inp in s:
                ans1.append(d[inp][0])
            else:
                ans1.append(-1)
        print(*ans1)

            