#####################################   
import atexit, io, sys, collections, math, heapq, fractions
buffer = io.BytesIO() 
sys.stdout = buffer
@atexit.register 
def write(): sys.__stdout__.write(buffer.getvalue())   
#####################################




def query(xi, ais, t, s):
	if len(t) == 0: return -1
	if t[-1][0] < xi and s <= 0:
		return -1
	if t[-1][0] >= xi:

		lo,hi = 0, len(t)-1
		while(lo < hi):
			med = (lo + hi)//2
			if t[med][0] >= xi:
				hi = med
			else:
				lo = med +1
		return t[lo][1]
	
	temp = xi - t[-1][0]
	ans = 0
	ans += (temp+s-1)/s * (len(ais))
	xi -= (temp+s-1)/s * s
	lo,hi = 0, len(t)-1
	while(lo < hi):
		med = (lo + hi)//2
		if t[med][0] >= xi:
			hi = med
		else:
			lo = med +1
	return ans + t[lo][1]
	

for u in range(int(raw_input())):
	n,m = map(int,raw_input().split())
	ais = map(int, raw_input().split())
	xis = map(int, raw_input().split())
	pis= ais[::]
	for i in range(1, len(ais)):
		pis[i] += pis[i-1]

	m = -1
	t = []
	for j in range(len(pis)):
		if pis[j] > m:
			t.append((pis[j], j))
			m = pis[j]
	s=  sum(ais)
	print ' '.join(map(str,[query(xi,ais,t,s) for xi in xis]))