def indexo(a,listo):
    try:
        index_value = listo.index(a)
    except ValueError:
        index_value = -1
    return   index_value
 
    
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    x=list(map(int,input().split()))
    l2=[]
    sumi=0
    for j in range(n):
        
        sumi=sumi+l[j]
        l2.append(sumi)
    maxi=l2[n-1]
    l3=[]
    for j in range(m):
        if not(maxi==0):
            div=x[j]// maxi
        mod=x[j]% maxi
        indexoo=indexo(mod,l2)
        if maxi==0 or x[j]*maxi<0:
            l3.append(indexoo)
        
        elif  not(mod==0)  and indexoo==-1:
            l3.append(-1)
        else:
            l3.append(div*n+indexoo)
    print(*l3, sep=' ')        
    
        
        
    
