import sys
import bisect
input=lambda: sys.stdin.readline().strip("\r\n")
from math import log
sa=lambda :input()
sb=lambda:int(input())
sc=lambda:input().split()
sd=lambda:list(map(int,input().split()))
se=lambda:float(input())
sf=lambda:list(input())
flsh=lambda: sys.stdout.flush()
mod=10**9+7
def hnbhai():
    n,m=sd()
    a=sd()
    query=sd()
    prefix=[0]*(n+2)
    d={}
    for i in range(1,n+1):
        prefix[i]=prefix[i-1]+a[i-1]
        if d.get(prefix[i]) is not None:
            continue
        d[prefix[i]]=i
    ans=list(d.keys())
    ans.sort()
    abe=[]
    for i in range(m):
        ind=bisect.bisect_left(ans,query[i])
        if ind!=len(ans):
            abe.append(d[ans[ind]]-1)
        else:
            if prefix[n]<=0:
                abe.append(-1)
            else:
                x=query[i]
                op=(x//prefix[n])*n
                rem=x%prefix[n]
                if rem==0:
                    abe.append(op-1)
                else:
                    ind=bisect.bisect_left(ans,rem)
                    if ind==len(ans):
                        abe.append(-1)
                        continue
                    op+=d[ans[ind]]
                    abe.append(op-1)
    print(*abe)
for _ in range(sb()):
    hnbhai()
