import math
from bisect import bisect_left, bisect_right
import sys

def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))

T = int(input())
for _ in range(T):
    N, M = get_ints()
    A = get_ints()
    X = get_ints()

    Q = []
    for i in range(M):
        Q.append((X[i], i))
    Q.sort()

    last_val = 0
    presum = []
    sort_presum = []
    max_val = float('-inf')
    for i in range(N):
        presum.append(last_val + A[i])
        sort_presum.append((last_val + A[i], i))
        last_val += A[i]
        max_val = max(max_val, presum[-1])
    sort_presum.sort()

    vis = {}
    q_idx = 0
    p_idx = 0
    while q_idx < len(Q):
        val, idx = Q[q_idx]
        if val <= presum[0]:
            vis[idx] = 0

        elif max_val < val:
            if presum[-1] <= 0:
                vis[idx] = -1
            else:
                t = math.ceil((val - max_val) / presum[-1])
                i = bisect_left(sort_presum, (val - t * presum[-1], 0))
                vis[idx] = t * len(presum) + sort_presum[i][1]

        else:
            i = bisect_left(sort_presum, (val, 0))
            vis[idx] = sort_presum[i][1]

        # else:
        #     while p_idx < len(presum) and presum[p_idx] < val:
        #         p_idx += 1
        #     vis[idx] = p_idx

        q_idx += 1

    # print(vis)
    ans = [str(vis[i]) for i in range(M)]
    print((" ").join(ans))
