t = int(input())
for inputs in range(t):
	m,n = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	xarr = [int(x) for x in input().split(' ')]
	suma = sum(arr)
	ans = [0 for x in xarr]
	xarr1 = [0 for x in xarr]
	if suma !=0:
		for x in range(len(xarr)):
			if xarr[x]!=suma and xarr[x] not in arr:
				ans[x] = ((int(xarr[x]/suma))*n)
				xarr1[x] = (xarr[x]%suma)
			else:
				ans[x] = 0
				xarr1[x] = xarr[x]
			
		for i in range(len(xarr1)):
			if(xarr1[i]<0):
				xarr1[i] = xarr[i]
		#print(xarr)
		#print(xarr1)
		xarr = xarr1
	else:
		ans = [0 for x in xarr]
	
	#print(xarr)
	#print(ans)
	for x,an in zip(xarr,ans):
		if x==0 and an>0:
			an = an-1
		if x != 0:
			for a in arr:
				x = x-a
				if x>0:
					an = an + 1 
				else:
					break
		if x<=0 and an>=0:
			print(an, end =" ")
		else:
			print("-1", end =" ")
	print()