import bisect

def main():
    t = int(input())
    for _ in range(t):
        n, m = map(int, input().split())
        a = list(map(int, input().split()))
        x = list(map(int, input().split()))
        d = {}; pts = []
        suma = M = 0
        for i in range(n):
            suma += a[i]
            if suma > M:
                M = suma
                pts.append(suma)
                d[suma] = i
        p = []
        for i in range(m):
            xi = x[i]
            if not pts:
                p.append(-1); continue
            if suma <= 0:
                if xi <= pts[-1]:
                    res = bisect.bisect_left(pts, xi)
                    p.append(d[pts[res]])
                else:
                    p.append(-1)
            else:
                laps = xi // pts[-1]
                if xi % pts[-1] == 0:
                    p.append((laps - 1) * n + d[pts[-1]])
                else:
                    total = n * laps
                    xi -= suma * laps
                    idx = bisect.bisect_left(pts, xi)
                    total += d[pts[idx]]
                    p.append(total)
        print(*p)
main()