import bisect
T=int(input())
for _ in range(T):
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    #print(_+1, n,m,A,B)
    ps=[i for i in A]
    for i in range(1,n):
        ps[i]=ps[i]+ps[i-1]
    pref=[[A[0],0]]
    for i in range(1,n):
        if (ps[i]>ps[i-1]):
            pref.append([ps[i],i])

    s=ps[-1]
    pref.sort()
    mv=pref[-1][0]
    ind=pref[-1][1]
    ans=[]
    #print(mv,pref)
    if (s<=0):
        for x in B:
            if (x>mv):
                ans.append(-1)
            else:
                v=bisect.bisect_left(pref,[x,0])
                ans.append(pref[v][1])
    else:
        for x in B:
            if (x<=mv):
                v=bisect.bisect_left(pref,[x,0])
                ans.append(pref[v][1])
            else:
                v1=((x-mv+s-1)//s)
                x=x-(v1*mv)
                v1=v1*n
                v=bisect.bisect_left(pref,[x,0])
                v=pref[v][1]
                v=v+v1
                ans.append(v)
    print(*ans)
                
                
