import sys
from itertools import accumulate
from collections import defaultdict
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def solve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    X = list(map(int, input().split()))

    ind_A = defaultdict(int)
    for i, a in enumerate(accumulate(A)):
        ind_A[a] = min(ind_A.get(a, f_inf), i)

    step = sum(A)
    res = [-1] * m
    if step == 0:
        for i, x in enumerate(X):
            if ind_A.get(x) is None:
                continue
            res[i] = ind_A[x]
    else:
        mod_step = defaultdict(list)
        for a in accumulate(A):
            mod_step[a % step].append(a)

        for k in mod_step.keys():
            mod_step[k].sort()

        for i, x in enumerate(X):
            x_mod = x % step
            if not mod_step[x_mod]:
                continue
            if step > 0:
                idx = bisect_right(mod_step[x_mod], x)
                b = mod_step[x_mod][idx - 1 if idx else idx]
            else:
                idx = bisect_left(mod_step[x_mod], x)
                b = mod_step[x_mod][idx if idx < len(mod_step[x_mod]) else idx - 1]
            loop = (x - b) // step
            if loop < 0:
                continue
            res[i] = ind_A[b] + loop * n
    print(*res)


def resolve():
    t = int(input())
    for _ in range(t):
        solve()


if __name__ == '__main__':
    resolve()
