#!/usr/bin/python

import sys

def solve_mini(A, q, my_sum, my_max):
    if my_sum <= 0 and my_max < q:
        return -1
    else:
        full_round = (q - my_max - 1) // my_sum + 1
        print("full_round ", full_round)
        done = my_sum * full_round
        steps = len(A) * full_round
        to_go = q - done
        curr = 0
        for i in range(len(A)):
            steps += 1
            curr += A[i]
            if curr >= to_go:
                break
        return steps - 1
        
        
def solve(A, Q):
    my_sum = sum(A)
    my_max = 0
    my_val = 0
    for a in A:
        my_val += a
        if my_val > my_max:
            my_max = my_val
    #when it cannot reach
    res = []
    for q in Q:
        res.append(solve_mini(A, q, my_sum, my_max))
    print(" ".join([str(r) for r in res]))
    #which round is it going to reach


def run():
    out = ""    
    T = int(input())
    for i in range(T):
        N, M = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]
        Q = [int(x) for x in input().split()]
        solve(A, Q)

run()

