#!/usr/bin/env python3

import bisect

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = [int(i) for i in input().split()]
    x = [int(i) for i in input().split()]

    b = []
    s = 0
    for i in range(n):
        s += a[i]
        b.append((s, i))
    b.sort()

    sum_a = sum(a)

    ans = []

    for x_i in x:
        i = bisect.bisect_left(b, (x_i, ))
        if i != len(b):
            if b[i][0] == x_i:
                ans.append(b[i][1])
            else:
                ans.append(b[i][1] - 1)
        elif sum_a <= 0:
            ans.append(-1)
        else:
            r = (x_i - b[-1][0]) // sum_a
            ans_i = n * r
            x_i -= r * sum_a

            while True:
                i = bisect.bisect_left(b, (x_i, ))
                if i != len(b):
                    if b[i][0] == x_i:
                        ans_i += b[i][1]
                    else:
                        ans_i += b[i][1] - 1
                    break
                else:
                    ans_i += n
                    x_i -= sum_a
            ans.append(ans_i)
    print(" ".join([str(i) for i in ans]))
