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]
    ma = max(a)
    s = a[-1]
    
    ans = []
    for i in range(m):
        if s < 0:
            ans.append(-1)
            continue
        elif s == 0:
            if ma >= x[i]:
                h = 1
            else:
                ans.append(-1)
                continue
        else:
            h = x[i]//s + 1
        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)
        for j in range(n):
            if pre+a[j] >= x[i]:
                ans.append(preans+j)
                break
    print(' '.join(str(i) for i in ans))
    
        