import collections
from bisect import bisect_left
import math

def solveTestCase():
	n, m = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	vs = []
	poss = {}
	v = 0
	min_v = -1
	for i in range(len(a)):
		v += a[i]
		if v > min_v:
			min_v = v
			vs.append(v)
			if v not in poss:
				poss[v] = i+1

	vs.sort()
	new_n = len(vs)
	for i in b:
		if v <= 0 and (new_n == 0 or vs[-1]<i):
			print(-1, end=" ")
		else:
			nb_round = 0
			if v > 0:
				nb_round = math.ceil((i - vs[-1])/v)
			if nb_round < 0:
				nb_round = 0
			res = nb_round * n - 1
			rst = i - nb_round * v
			if rst > 0:
				pos = bisect_left(vs, rst, 0, -n)
				if vs[pos] < rst:
					pos += 1
				res += poss[vs[pos]]
			print(res, end=" ")




	print()
if __name__ == "__main__":
	t = int(input().split()[0])
	while t > 0:
		t -= 1
		solveTestCase()
