for j in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    t=a[0]
    p=[0]*n
    p[0]=a[0]
    for i in range(1,n):
        t+=a[i]
        p[i]=max(t,p[i-1])
    s=max(p)
    for x in b:
        l=-1
        r=10**10
        while r-l>1:
            m=(r+l)//2
            if x<=m*t+s:
                r=m
            else:
                l=m
        if l>10**9:
            print(-1,end=' ')
        else:
            time=n*r
            h=r*t
            l=-1
            r=n
            while r-l>1:
                m=(r+l)//2
                if h+p[m]>=x:
                    r=m
                else:
                    l=m
            print(time+r,end=' ')
    print()