import sys,functools,collections,bisect,math
input = sys.stdin.readline
#print = sys.stdout.write

t = int(input())
for _ in range(t):
    n,m = map(int,input().strip().split())
    a = list(map(int,input().strip().split()))
    x = list(map(int,input().strip().split()))
    for i in range(1,n):
        a[i] += a[i-1]
    anew = [(a[0],0)]
    for i in range(n):
        if anew[-1][0] < a[i]:
            anew.append((a[i],i))
    ma = anew[-1][0]
    s = a[-1]
    #print(anew)
    
    ans = []
    for i in range(m):
        if s <= 0:
            if ma >= x[i]:
                h = 1
            else:
                ans.append(-1)
                continue
        else:
            h = math.ceil(x[i]/s) 
        l = 0
        while l<h:
            mid = (h+l)//2 
            if s*mid+ma >= x[i]:
                h = mid
            else:
                l = mid+1
        preans = h*n
        pre = s*h
        #print(pre,preans)
        ind = bisect.bisect_left(anew,(x[i]-pre,0))
        ans.append(preans+anew[ind][1])
    print(' '.join(str(i) for i in ans))
    
        