import collections

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()]
	ok = {}
	v = 0
	for i in range(len(a)):
		v += a[i]
		if v not in ok:
			ok[v] = i

	for i in b:
		if i in ok:
			print(ok[i], end=" ")
		elif v <= 0:
			print(-1, end=" ")
		else:
			rst = i%v
			if rst == 0:
				print((i//v)*len(a)-1, end=" ")
			elif rst in ok:
				print(ok[rst]+((i//v)*len(a)), end=" ")
			else:
				print(-1, end=" ")
	print()
if __name__ == "__main__":
	t = int(input().split()[0])
	while t > 0:
		t -= 1
		solveTestCase()
