from collections import defaultdict
import bisect
import sys
input = sys.stdin.readline

t = int(input())
inf = 1145141919810
for _ in range(t):
    n, m = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    x = list(map(int, input().split()))
    for i in range(n):
        a[i + 1] += a[i]
    an = a[n]
    c = 1 if an >= 0 else -1
    if an:
        d = defaultdict(lambda : [])
        d0 = defaultdict(lambda : [])
        s = set()
        for i in range(1, n + 1):
            b = c * a[i]
            if not b in s:
                s.add(b)
                d[b % an].append([b, i])
        for i in d:
            d[i].append([inf, 0])
            d[i].append([-inf, 0])
            d[i].sort()
            for di in d[i]:
                d0[i].append(di[0])
        ans = []
        for i in x:
            b = c * i
            y = d0[b % an]
            z = d[b % an]
            if not y:
                ans.append(-1)
            else:
                j = bisect.bisect_left(y, b)
                k = j - 1
                if abs(b - y[k]) < abs(b - y[j]):
                    ans.append(abs(b - y[k]) // an * n + z[k][1] - 1)
                elif abs(b - y[j]) < abs(b - y[k]):
                    ans.append(abs(b - y[j]) // an * n + z[j][1] - 1)
                else:
                    if z[k][1] < z[j][1]:
                        ans.append(abs(b - y[k]) // an * n + z[k][1] - 1)
                    else:
                        ans.append(abs(b - y[j]) // an * n + z[j][1] - 1)
            if not ans[-1] // n * an + a[ans[-1] % n + 1] == i or ans[-1] < -1:
                ans[-1] = -1
    else:
        d = defaultdict(lambda : -1)
        for i in range(1, n + 1):
            if d[a[i]] == -1:
                d[a[i]] = i - 1
        ans = []
        for i in x:
            ans.append(d[i])
    print(*ans)