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():
    def meguru_bisect(ok, ng):
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ng = mid
            else:
                ok = mid
        return ng

    def is_ok(l):
        return True if B[-1] + l * step >= x else False

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

    B = list(accumulate(A))
    step = B[-1]
    B = [[B[i], i] for i in range(n)]
    B.sort()
    idx = [B[i][1] for i in range(n)]
    B = [B[i][0] for i in range(n)]
    ma = B[-1]

    res = [-1] * m
    for i in range(m):
        x = X[i]
        if x > ma and step <= 0:
            continue
        loop = meguru_bisect(-1, 10 ** 9 + 1)
        x -= loop * step
        j = bisect_left(B, x)
        res[i] = idx[j if j < n else j - 1] + loop * n
    print(*res)


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


if __name__ == '__main__':
    resolve()
