'''Author- Akshit Monga'''
from sys import stdin, stdout
from bisect import bisect_right
input = stdin.readline
t = int(input())
for _ in range(t):
	n,m=map(int,input().split())
	a=[int(x) for x in input().split()]
	b=[int(x) for x in input().split()]
	s=0
	d={}
	c=-1
	x=float('inf')
	for i in a:
		c+=1
		s+=i
		if s>0 and s<x:
			d[s]=c
			x=min(x,s)
	val1=0
	if s<0:
		val1=1
	# print(d)
	if len(d)==0:
		print(*[-1 for i in range(m)])
		continue
	maxi=max(d)
	vals=list(d.keys())
	# print(d,val1)
	for i in b:
		if i>maxi and val1:
			stdout.write("-1 ")
			continue
		steps=0
		while i>maxi:
			i-=s
			steps+=1
		# print(steps)
		val = bisect_right(vals,i)
		if val - 1 >= 0 and vals[val - 1] >= i:
			ans = n*steps+d[i]
		else:
			ans = n*steps+d[vals[val]]
		# print(ans)
		stdout.write(str(ans)+" ")
	print()