import sys
input=sys.stdin.buffer.readline

from collections import defaultdict

for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    x=list(map(int,input().split()))
    sum_a=[]
    add=0
    for i in range(n):
        add+=a[i]
        sum_a.append(add)
    mod=sum_a[-1]
    d= defaultdict()
    if(mod>0):
        for i in range(n):
            if(sum_a[i]>=0):
                p=sum_a[i]%mod
                q=sum_a[i]//mod
                if p in d and d[p][0]>q:
                    d[p][0]=q
                    d[p][1]=i
                else:
                    d[p]=list()
                    d[p].append(sum_a[i]//mod)
                    d[p].append(i)
        for i in range(m):
            y=x[i]%mod
            z=x[i]//mod
            if y in d and d[y][0]<=z:
                print((z-d[y][0])*n+d[y][1],end=' ')
            else:
                print(-1,end=' ')
    elif(mod<0):
        mod*=-1
        for i in range(n):
            if (sum_a[i] >= 0):
                p = sum_a[i] % mod
                q = sum_a[i] // mod
                if p in d and d[p][0] < q:
                    d[p][0] = q
                    d[p][1] = i
        for i in range(m):
            y=x[i]%mod
            z=x[i]//mod
            if y in d and d[y][0]>=z:
                print((d[y][0]-z)*(n-1)+d[y][1],end=' ')
            else:
                print(-1,end=' ')
    else:
        d= {}
        for i in range(n):
            if(sum_a[i]>=0):
                d[sum_a[i]]=i
        for i in range(m):
            if(x[i] in d):
                print(i,end=' ')
            else:
                print(-1)
    print()