import bisect

N = int(input())
def solve(n,m,a,x):
    B = []
    mx_pref = -float('inf')
    s = 0
    for i in range(len(a)):
        s += a[i]
        mx_pref = max(mx_pref, s)
        B.append(mx_pref)
    ans = []
    for xi in x:
        if xi > mx_pref and s <= 0:
            ans.append(-1)
            continue
        if xi <= mx_pref:
            ans.append(bisect.bisect_left(B,xi))
        else:
            res = 0
            lo,hi = 0,xi//s
            while lo+1 < hi:
                mid = (lo+hi)//2
                if xi-s*mid < mx_pref:
                    hi = mid
                else:
                    lo = mid
            ans.append((lo+1)*n-1)
            xi = xi - s*(lo+1)
            if xi > 0: ans[-1] += 1+bisect.bisect_left(B,xi)
    return ans

for _ in range(N):
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    x = list(map(int, input().split()))
    ans = solve(n,m,a,x)
    if _ == 34:
        print(n,m,a,x)
    print(" ".join(str(x) for x in ans))
