import math,sys,bisect,heapq,os
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
def input(): return sys.stdin.readline().rstrip('\r\n')
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda: list(map(int, input().split()))
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

def solve():
	for _ in range(int(input())):
		n,m= aj()
		A = aj()
		x = aj()
		s = sum(A)
		# print(A,x)
		A = list(accumulate(A))
		C = [max(0,A[0])]
		for i in range(1,len(A)):
			C.append(max(C[-1],A[i]))
		# print(C)
		m = C[-1]
		Ans = []
		if m == 0:
			Ans = [-1]*len(x)
		else:
			if s > 0:
				for i in x:
					if i <= m:
						a = bisect.bisect_left(C,i)
					else:
						a = (i//m)*n
						# print(i%m)
						if i % m != 0:
							a += bisect.bisect_left(C,i%m)
						else:
							a-=1
							b = a - n
							b += bisect.bisect_left(C,m) + 1
							a = min(a,b)
					Ans.append(a)
			else:
				for i in x:
					if i > m:
						Ans.append(-1)
					else:
						Ans.append(bisect.bisect_left(C,i))

		print(*Ans)





try:
	#os.system("online_judge.py")
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass

solve()

