from bisect import *
a=int(input())
for i in range(a):
    n,m=map(int,input().split())
    z=list(map(int,input().split()))
    x=list(map(int,input().split()))
    for i in range(1,len(z)):
        z[i]+=z[i-1]
    maxa=[]
    for i in range(len(z)):
        if(i==0):
            maxa.append(z[0])
        else:
            maxa.append(max(maxa[-1],z[i]))
    
    for i in range(len(x)):
        r=bisect_left(maxa,x[i])
        
        if(r==len(maxa) and z[-1]<=0):
            print(-1,end=" ")
        else:
            if(r<len(maxa)):
                print(r,end=" ")
            else:
                cycles=x[i]//z[-1]
                rem=x[i]%z[-1]
               
                total=((cycles-1)*len(z))+(len(z)-1)
                if(rem!=0):
                    print(total+bisect_left(maxa,rem)+1,end=" ")
                else:
                    cycles-=1
                    value=z[-1]
                    r=bisect_left(maxa,value)
                    if(cycles==0):
                        print(r)
                    else:
                        total=((cycles-1)*len(z))+(len(z)-1)
                        print(total+r+1,end=" ")
                        
                    
    print(' ')
                
        
