from collections import defaultdict
import sys
input=sys.stdin.readline 
for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    x=list(map(int,input().split()))
    pref=[a[0] for i in range(n)]
    d=defaultdict(int)
    d[pref[0]]=1
    for i in range(1,n):
        pref[i]=pref[i-1]+a[i]
        d[pref[i]]=i+1
    for q in range(m):
        if pref[n-1]<=0 and d[x[q]]<1:
            print(-1,end=" ")
        elif d[x[q]]:
            print(d[x[q]]-1,end=" ")
        else :
            ans=1e15
            for i in range(n):
                if (x[q]-pref[i])%pref[n-1]==0 and (x[q]-pref[i])//(pref[n-1]) >0:
                    ans=min(ans,((x[q]-pref[i])//pref[n-1])*n+i)
            if ans ==1e15 :
                ans=-1
            print(ans,end=" ")
    print("")

