Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with $n$ integers written on it.

Polycarp wrote the numbers from the disk into the $a$ array. It turned out that the drive works according to the following algorithm:

the drive takes one positive number $x$ as input and puts a pointer to the first element of the $a$ array;

after that, the drive starts rotating the disk, every second moving the pointer to the next element, counting the sum of all the elements that have been under the pointer. Since the disk is round, in the $a$ array, the last element is again followed by the first one;

as soon as the sum is at least $x$, the drive will shut down.

Polycarp wants to learn more about the operation of the drive, but he has absolutely no free time. So he asked you $m$ questions. To answer the $i$-th of them, you need to find how many seconds the drive will work if you give it $x_i$ as input. Please note that in some cases the drive can work infinitely.

For example, if $n=3, m=3$, $a=[1, -3, 4]$ and $x=[1, 5, 2]$, then the answers to the questions are as follows:

the answer to the first query is $0$ because the drive initially points to the first item and the initial sum is $1$.

the answer to the second query is $6$, the drive will spin the disk completely twice and the amount becomes $1+(-3)+4+1+(-3)+4+1=5$.

the answer to the third query is $2$, the amount is $1+(-3)+4=2$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case consists of two positive integers $n$, $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the number of numbers on the disk and the number of asked questions.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$).

The third line of each test case contains $m$ positive integers $x_1, x_2, \ldots, x_m$ ($1 \le x \le 10^9$).

It is guaranteed that the sums of $n$ and $m$ over all test cases do not exceed $2 \cdot 10^5$.


-----Output-----

Print $m$ numbers on a separate line for each test case. The $i$-th number is:

$-1$ if the drive will run infinitely;

the number of seconds the drive will run, otherwise.


-----Examples-----

Input
3
3 3
1 -3 4
1 5 2
2 2
-2 0
1 2
2 2
0 1
1 2
Output
0 6 2 
-1 -1 
1 3


-----Note-----

None

Difficulty: HARD
Tags: Sorting

Data structures

Mathematics
Skill types: Sorting

Data structures

Starter code:

Solutions:
import bisect
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [0] * n
	check_point = []
	cnt = 0
	for i in range(n):
		if i == 0:
			dp[i] = a[i]
		else:
			dp[i] = dp[i - 1] + a[i]
		if cnt == 0 and dp[i] > 0:
			check_point.append((dp[i], i))
			cnt += 1
		elif cnt != 0 and dp[i] > check_point[cnt - 1][0]:
			check_point.append((dp[i], i))
			cnt += 1
	for i in range(m):
		ans = -1
		if cnt != 0:
			if b[i] > check_point[cnt - 1][0] and dp[n - 1] > 0:
				tmp = b[i]
				tmp -= check_point[cnt - 1][0]
				if tmp % dp[n - 1] == 0:
					ans = tmp // dp[n - 1] * n + check_point[cnt - 1][1]
				else:
					to_find = b[i] - (tmp // dp[n - 1] + 1) * dp[n - 1]
					pos = bisect.bisect_left(check_point, (to_find, 0))
					ans = (tmp // dp[n - 1] + 1) * n + check_point[pos][1]
			elif b[i] > check_point[cnt - 1][0]:
				ans = -1
			else:
				pos = bisect.bisect_left(check_point, (b[i], 0))
				ans = check_point[pos][1]
		print(ans, end=' ')
	print()


from __future__ import division, print_function
from itertools import permutations
import threading, bisect, math, heapq, sys
from collections import deque
from sys import stdin, stdout
i_m = 9223372036854775807

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
prime = []

def dfs(n, d, v):
	v[n] = 1
	x = d[n]
	for i in x:
		if i not in v:
			dfs(i, d, v)
	return p

def block(x):
	v = []
	while x > 0:
		v.append(int(x % 2))
		x = int(x / 2)
	ans = []
	for i in range(0, len(v)):
		if v[i] == 1:
			ans.append(2 ** i)
	return ans

def main():
	t = inin()
	for _ in range(t):
		(n, m) = cin()
		a = ain()
		f = sum(a)
		b = ain()
		s = []
		p = 0
		ans = []
		for i in range(n):
			p += a[i]
			q = p
			if len(s) > 0:
				q = s[-1]
			s.append(max(q, p))
		for x in b:
			if s[-1] < x and f <= 0:
				ans.append(-1)
				continue
			an = 0
			if x > s[-1]:
				p = (x - s[-1]) / f
				p = math.ceil(p)
				x = x - p * f
				an = n * p
			if x > 0:
				q = bisect.bisect_left(s, x)
			ans.append(an + q)
		print(*ans)

def intersection(l, r, ll, rr):
	if ll > r or rr < l:
		return 0
	else:
		l = max(l, ll)
		r = min(r, rr)
	return max(0, r - l + 1)
fac = []

def fact(n, mod):
	global fac
	fac.append(1)
	for i in range(1, n + 1):
		fac.append(fac[i - 1] * i % mod)
	f = fac[:]
	return f

def nCr(n, r, mod):
	global fac
	x = fac[n]
	y = fac[n - r]
	z = fac[r]
	x = moddiv(x, y, mod)
	return moddiv(x, z, mod)

def moddiv(m, n, p):
	x = pow(n, p - 2, p)
	return m * x % p

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	ll = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				ll.append(n // i)
	l.extend(ll[::-1])
	return l

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f

def primeFactors(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			a.append(i)
			n = n // i
	if n > 2:
		a.append(n)
	return a
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'R'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'R'[0]:
		A.append(sign * numb)
	return A
main()


for k in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	b = 0
	c = 0
	d = 0
	e = []
	y = []
	n1 = 0
	for i in range(n):
		if d == 0:
			if a[i] > 0:
				b += a[i]
				e.append([b, i])
				n1 += 1
			else:
				d = 1
				c = a[i]
		else:
			c += a[i]
			if c > 0:
				d = 0
				e.append([b + c, i])
				b += c
				n1 += 1
				c = 0
	f = b + c
	if e == []:
		y = [-1 for i in range(m)]
	else:
		g = e[-1][0]
		for i in range(m):
			if x[i] <= g:
				l = n1 / 2
				h = round(l)
				while round(l) > 0:
					if e[h][0] < x[i]:
						h = min(n1 - 1, h + round(l / 2))
					else:
						h = max(0, h - round(l / 2))
					l /= 2
				h -= 1
				while h > 0 and e[h][0] == e[h + 1][0]:
					h -= 1
				h = max(h, 0)
				while e[h][0] < x[i]:
					h += 1
				y.append(e[h][1])
			elif f > 0:
				x1 = (x[i] - g) // f
				if (x[i] - g) % f != 0:
					x1 += 1
				x[i] -= x1 * f
				l = n1 / 2
				h = round(l)
				while round(l) > 0:
					if e[h][0] < x[i]:
						h = min(n1 - 1, h + round(l / 2))
					else:
						h = max(0, h - round(l / 2))
					l /= 2
				h -= 1
				while h > 0 and e[h][0] == e[h + 1][0]:
					h -= 1
				h = max(h, 0)
				while e[h][0] < x[i]:
					h += 1
				y.append(e[h][1] + n * x1)
			else:
				y.append(-1)
	print(*y)


import sys
from bisect import bisect_left
from itertools import accumulate

def solve(n, m, a, x):
	p = list(accumulate(a))
	s = p[-1]
	for i in range(1, n):
		p[i] = max(p[i], p[i - 1])
	ans = list()
	for i in range(m):
		if s <= 0 and x[i] > p[-1]:
			ans.append(-1)
			continue
		elif s <= 0 or x[i] <= p[-1]:
			k = 0
		else:
			k = (x[i] - p[-1]) // s
			if (x[i] - p[-1]) % s > 0:
				k += 1
		x[i] -= k * s
		index = bisect_left(p, x[i])
		ans.append(k * n + index)
	return ans

def main(argv=None):
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		x = list(map(int, input().split()))
		print(' '.join(map(str, solve(n, m, a, x))))
	return 0
STATUS = main()
sys.exit(STATUS)


import sys, functools, collections, bisect, math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	x = list(map(int, input().strip().split()))
	for i in range(1, n):
		a[i] += a[i - 1]
	anew = [(a[0], 0)]
	for i in range(n):
		if anew[-1][0] < a[i]:
			anew.append((a[i], i))
	ma = anew[-1][0]
	s = a[-1]
	ans = []
	for i in range(m):
		if s <= 0:
			if ma >= x[i]:
				h = 1
			else:
				ans.append(-1)
				continue
		else:
			h = math.ceil(x[i] / s)
		l = 0
		while l < h:
			mid = (h + l) // 2
			if s * mid + ma >= x[i]:
				h = mid
			else:
				l = mid + 1
		preans = h * n
		pre = s * h
		ind = bisect.bisect_left(anew, (x[i] - pre, 0))
		ans.append(preans + anew[ind][1])
	print(' '.join((str(i) for i in ans)))


import sys
from bisect import bisect_left
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def solve():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	X = list(map(int, input().split()))
	pref = []
	ind = []
	step = 0
	for (i, a) in enumerate(A):
		step += a
		if not pref or step > pref[-1]:
			pref.append(step)
			ind.append(i)
	res = [0] * m
	for (j, x) in enumerate(X):
		if pref[-1] < x and step <= 0:
			res[j] = -1
		else:
			loop = 0
			if pref[-1] < x:
				loop = (x - pref[-1] + step - 1) // step
			x -= loop * step
			idx = bisect_left(pref, x)
			res[j] = loop * n + ind[idx]
	print(*res)

def resolve():
	t = int(input())
	for t in range(t):
		solve()
resolve()


from collections import defaultdict
from bisect import bisect_right
import math
t = int(input())
for i in range(t):
	(n, u) = map(int, input().split())
	b = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ans = []
	s = sum(b)
	pre = [0]
	for j in range(n):
		pre.append(pre[-1] + b[j])
	st = [0]
	d = defaultdict(lambda : 0)
	d[0] = 0
	j = 1
	while j <= n:
		if pre[j] > st[-1]:
			st.append(pre[j])
			d[pre[j]] = j
		j += 1
	m = max(pre)
	res = []
	for j in range(u):
		if pre[-1] <= 0:
			if a[j] > m:
				res.append(-1)
			else:
				ind = d[st[bisect_right(st, a[j] - 1)]]
				res.append(ind - 1)
		else:
			if a[j] <= m:
				k = 0
				req = a[j]
			else:
				k = math.floor((a[j] - m) / pre[-1])
				req = a[j] - k * pre[-1]
				if req > m:
					k += 1
					req = a[j] - k * pre[-1]
			ind = d[st[bisect_right(st, req - 1)]]
			res.append(max(0, k * n + ind - 1))
	print(*res)


from bisect import bisect_left
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	p = [0] * (n + 1)
	M = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = p[i] + a[i]
		M[i + 1] = max(M[i], p[i + 1])
	s = p[-1]
	ans = []
	for x in map(int, input().split()):
		r = 0
		if s > 0:
			t = max((x - M[-1] + s - 1) // s, 0)
			r += t * n
			x -= t * s
		ans.append('-1' if x > M[-1] else str(r + bisect_left(M, x) - 1))
	print(' '.join(ans))


import io
import os
from collections import Counter, defaultdict, deque
from bisect import bisect_left

def solve(N, M, A, X):
	pref = [0]
	for x in A:
		pref.append(pref[-1] + x)
	for i in range(1, N + 1):
		pref[i] = max(pref[i], pref[i - 1])
	pref.pop(0)
	cycleLen = N
	cycleSum = sum(A)
	excess = max(0, pref[-1] - cycleSum)
	ans = []
	for x in X:
		t = bisect_left(pref, x)
		if t < len(pref) and pref[t] >= x:
			ans.append(t)
		elif cycleSum <= 0:
			ans.append(-1)
		else:
			fullCycles = (x - excess - 1) // cycleSum
			x -= cycleSum * fullCycles
			base = fullCycles * cycleLen
			assert 0 <= x <= pref[-1]
			t = bisect_left(pref, x)
			ans.append(base + t)
	return ' '.join(map(str, ans))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	X = [int(x) for x in input().split()]
	ans = solve(N, M, A, X)
	print(ans)


import math

def answer(n, a, m):
	s = 0
	max_sum = a[0]
	p_sums = [(a[0], 1)]
	for i in range(n):
		s += a[i]
		if s > max_sum:
			max_sum = s
			p_sums.append((s, i + 1))
	length = len(p_sums)
	x = list(map(int, input().split()))
	for i in range(m):
		xi = x[i]
		if s <= 0 and max_sum < xi:
			print(-1, end=' ')
			continue
		if xi <= max_sum:
			rounds = 0
		else:
			rounds = math.ceil((xi - max_sum) / s)
		xi -= rounds * s
		l = 0
		r = length - 1
		while l < r:
			mid = (l + r) // 2
			if p_sums[mid][0] < xi:
				l = mid + 1
			else:
				r = mid
		print(rounds * n + p_sums[l][1] - 1, end=' ')
	print('')
t = int(input())
for i in range(t):
	[n, m] = list(map(int, input().split()))
	a = list(map(int, input().split()))
	answer(n, a, m)


from itertools import accumulate
import bisect

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	p = list(accumulate(a))
	s = p[-1]
	max_val = max(p)
	for i in range(1, n):
		p[i] = max(p[i], p[i - 1])
	res = []
	for xi in x:
		if s <= 0 and xi > max_val:
			res.append(-1)
			continue
		cnt = 0
		if xi > max_val:
			c = (xi - max_val + s - 1) // s
			cnt += c * n
			xi -= c * s
		idx = bisect.bisect_left(p, xi)
		res.append(cnt + idx)
	return res
t = int(input())
for _ in range(t):
	print(*solve())


import bisect
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	x = list(map(int, input().split()))
	prefix = []
	dic = {}
	sum1 = 0
	for i in range(len(lis)):
		sum1 += lis[i]
		if prefix and sum1 < prefix[-1]:
			continue
		prefix.append(sum1)
		if sum1 not in dic:
			dic[sum1] = i
	l2 = []
	for i in range(len(prefix)):
		l2.append(prefix[i])
	l2.sort()
	output = []
	for i in x:
		if lis[0] >= i:
			output.append(0)
			continue
		if l2[-1] < i and sum1 <= 0:
			output.append(-1)
			continue
		if sum1 > 0 and l2[-1] < i:
			temp = i - l2[-1]
			rotations = math.ceil(temp / sum1)
			find = i - rotations * sum1
			output.append(len(lis) * rotations + dic[l2[bisect.bisect_left(l2, find)]])
			continue
		if l2[-1] >= i:
			output.append(dic[l2[bisect.bisect_left(l2, i)]])
	for i in output:
		print(i, end=' ')
	print()


import bisect
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	pre = 0
	max_e = -float('inf')
	min_e = float('inf')
	s = []
	for j in range(n):
		pre += a[j]
		if pre > max_e:
			max_e = pre
			s.append((pre, j))
	res = []
	for xi in x:
		if pre <= 0:
			index = bisect.bisect_left(s, (xi, 0))
			if index == len(s):
				res.append(-1)
			else:
				res.append(s[index][-1])
		else:
			cur = 0
			loop = 0
			if xi > s[-1][0]:
				loop = (xi - s[-1][0] - 1) // pre + 1
				cur += loop * n
			xi -= loop * pre
			index = bisect.bisect_left(s, (xi, 0))
			res.append(s[index][-1] + cur)
	print(*res)


from bisect import bisect_left
import math
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(n, m) = li()
	a = li()
	xl = li()
	mx = []
	curSum = 0
	mxind = []
	res = []
	for i in range(n):
		curSum += a[i]
		if mx == [] or mx[-1] < curSum:
			mx.append(curSum)
			mxind.append(i)
	for x in xl:
		if x > mx[-1] and curSum <= 0:
			res.append(-1)
		else:
			temp = 0
			if x > mx[-1]:
				dif = x - mx[-1]
				temp = math.ceil(dif / curSum)
			res.append(temp * n + mxind[bisect_left(mx, x - temp * curSum)])
	print(*res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))
import math

def find(x, now):
	if tree[now] < x:
		return -1
	if now >= nn:
		return now - nn
	t = find(x, now << 1)
	if t >= 0:
		return t
	return find(x, now << 1 | 1)
for _ in range(N()):
	(n, _) = RL()
	(a, x) = (RLL(), RLL())
	s = [0]
	for v in a:
		s.append(s[-1] + v)
	nn = 1 << (n + 1).bit_length()
	tree = [0] * nn + s + [0] * (nn - n - 1)
	for i in range(nn - 1, 0, -1):
		tree[i] = max(tree[i << 1], tree[i << 1 | 1])
	ans = []
	for v in x:
		if s[-1] <= 0 and tree[1] < v:
			ans.append(-1)
			continue
		k = 0 if v <= tree[1] else math.ceil((v - tree[1]) / s[-1])
		ans.append(k * n + find(v - k * s[-1], 1) - 1)
	print_list(ans)


import sys
from bisect import bisect_left
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	p = [0] * (n + 1)
	M = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = p[i] + a[i]
		M[i + 1] = max(M[i], p[i + 1])
	s = p[-1]
	ans = []
	for x in map(int, input().split()):
		r = 0
		if s > 0:
			t = max((x - M[-1] + s - 1) // s, 0)
			r += t * n
			x -= t * s
		if x > M[-1]:
			ans.append('-1')
		else:
			pos = bisect_left(M, x)
			ans.append(str(r + pos - 1))
	print(' '.join(ans))
for i in range(int(input())):
	solve()


import sys
import bisect
input = lambda : sys.stdin.readline().strip('\r\n')
from math import log
sa = lambda : input()
sb = lambda : int(input())
sc = lambda : input().split()
sd = lambda : list(map(int, input().split()))
se = lambda : float(input())
sf = lambda : list(input())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7

def hnbhai():
	(n, m) = sd()
	a = sd()
	query = sd()
	prefix = [0] * (n + 1)
	d = {}
	max_ = [0] * (n + 1)
	for i in range(1, n + 1):
		prefix[i] = prefix[i - 1] + a[i - 1]
		max_[i] = max(max_[i - 1], prefix[i])
		if d.get(prefix[i]) is not None:
			continue
		if prefix[i] > 0:
			d[prefix[i]] = i - 1
	abe = []
	for i in range(m):
		op = 0
		ind = bisect.bisect_left(max_, query[i])
		if ind != len(max_):
			abe.append(ind - 1)
		else:
			if prefix[n] <= 0:
				abe.append(-1)
				continue
			if max_[-1] < query[i]:
				ans = query[i] - max_[-1]
				op = ans // prefix[n]
				if ans % prefix[n]:
					op += 1
				query[i] -= op * prefix[n]
				op = n * op
			abe.append(op + bisect.bisect_left(max_, query[i]) - 1)
	print(*abe)
for _ in range(sb()):
	hnbhai()


t = int(input())
import math
import heapq
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	lis = [a[0]]
	for i in range(1, n):
		lis.append(lis[-1] + a[i])
	one_round = lis[-1]
	MAX = max(lis)
	rests = []
	ans = []
	for q in x:
		if MAX < q:
			if one_round <= 0:
				pass
			else:
				round = math.ceil((q - MAX) / one_round)
				rest = q - round * one_round
				rests.append(rest)
		else:
			rests.append(q)
	heapq.heapify(rests)
	dic = dict()
	for i in range(n):
		while True:
			if len(rests) == 0 or rests[0] > lis[i]:
				break
			temp = heapq.heappop(rests)
			dic[temp] = i
	for q in x:
		if MAX < q:
			if one_round <= 0:
				ans.append(-1)
			else:
				round = math.ceil((q - MAX) / one_round)
				rest = q - round * one_round
				ans.append(dic[rest] + round * n)
		else:
			ans.append(dic[q])
	print(' '.join((str(n) for n in ans)))


import bisect
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	X = list(map(int, input().split()))
	upd = [0]
	updl = [0]
	m = 0
	cum = 0
	for (i, a) in enumerate(A):
		cum += a
		if m < cum:
			m = cum
			upd.append(m)
			updl.append(i)
	ans = []
	for x in X:
		if x > m and cum <= 0:
			ans.append(-1)
			continue
		if x <= m:
			ind = bisect.bisect_right(upd, x)
			if upd[ind - 1] >= x:
				ans.append(updl[ind - 1])
			else:
				ans.append(updl[ind])
		else:
			c = (x - m + cum - 1) // cum
			base = c * n
			x = x - cum * c
			ind = bisect.bisect_right(upd, x)
			if upd[ind - 1] >= x:
				ans.append(base + updl[ind - 1])
			else:
				ans.append(base + updl[ind])
	print(*ans)


from bisect import bisect_left
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	curSum = 0
	mx = []
	mxindx = []
	for i in range(n):
		curSum += a[i]
		if mx == [] or mx[-1] < curSum:
			mx.append(curSum)
			mxindx.append(i)
	stack = []
	for i in range(m):
		if x[i] > mx[-1] and curSum <= 0:
			stack.append(-1)
		else:
			temp = 0
			if x[i] > mx[-1]:
				diff = x[i] - mx[-1]
				temp = math.ceil(diff / curSum)
			stack.append(temp * n + mxindx[bisect_left(mx, x[i] - curSum * temp)])
	print(*stack)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
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)]

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()
		A = [0] + list(accumulate(A))
		C = [0]
		for i in range(1, len(A)):
			C.append(max(C[-1], A[i]))
		m = C[-1]
		s = A[-1]
		Ans = []
		if m == 0:
			Ans = [-1] * len(x)
		else:
			for i in x:
				if i > m and s <= 0:
					Ans.append(-1)
				else:
					a = 0
					if s > 0 and i > m:
						a += (i - m + s - 1) // s
					k = bisect.bisect_left(C, i - a * s)
					Ans.append(a * n + k - 1)
		print(*Ans)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = 998244353

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return --1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			if i % j == 0:
				break
	return primes

def solve():
	(n, m) = map(int, input().split())
	a = [int(i) for (p, i) in enumerate(input().split())]
	mx = -1145141919810931
	su = 0
	ans = [0 for i in range(m)]
	for i in a:
		su += i
		mx = max(mx, su)
	s = sum(a)
	x = [[int(i), p] for (p, i) in enumerate(input().split())]
	if s > 0:
		for (p, pp) in enumerate(x):
			(i, j) = pp
			if i > mx:
				lop = math.ceil((i - mx) / s)
				ans[j] += lop * n
				x[p][0] -= math.ceil((i - mx) / s) * s
	x.sort(reverse=True)
	su = 0
	sec = 0
	for i in a:
		su += i
		if not x:
			break
		else:
			while x:
				if x[-1][0] <= su:
					ans[x[-1][1]] += sec
					x.pop()
				else:
					break
		sec += 1
	if s <= 0:
		while x:
			(t, pos) = x.pop()
			ans[pos] = -1
	print(*ans)
t = int(input())
for ti in range(t):
	solve()


from sys import stdin
input = stdin.buffer.readline
import math

def func(dp, start, end, x):
	pos = -1
	while start <= end:
		mid = (start + end) // 2
		if dp[mid][0] >= x:
			pos = mid
			end = mid - 1
		else:
			start = mid + 1
	return pos
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	query = [int(x) for x in input().split()]
	x = 0
	dp = []
	for i in range(n):
		x = x + arr[i]
		dp.append((x, i))
	s = x
	dp.sort()
	stack = [-1] * n
	mn = 1000000
	for i in range(n - 1, -1, -1):
		mn = min(mn, dp[i][1])
		stack[i] = mn
	ans = []
	for q in query:
		if dp[-1][0] <= 0:
			ans.append(-1)
			continue
		if q <= dp[-1][0]:
			x = func(dp, 0, n - 1, q)
			ans.append(stack[x])
			continue
		if s <= 0:
			ans.append(-1)
			continue
		c = math.ceil((q - dp[-1][0]) / s)
		new_ans = c * n
		q = q - c * s
		x = func(dp, 0, n - 1, q)
		ans.append(new_ans + stack[x])
	print(*ans)


import heapq

def solve(n, a, x):
	delta = sum(a)
	offset = [0] * len(x)
	if delta > 0:
		mx = None
		s = 0
		for i in range(n):
			s += a[i]
			if mx is None or mx < s:
				mx = s
		offset = [0] * len(x)
		for i in range(len(x)):
			laps = (max(0, x[i] - mx) + delta - 1) // delta
			offset[i] = laps * n
			x[i] -= laps * delta
	q = []
	for i in range(len(x)):
		heapq.heappush(q, (x[i], i))
	s = 0
	res = [-1] * len(x)
	for i in range(n):
		s += a[i]
		while q and s >= q[0][0]:
			res[q[0][1]] = i + offset[q[0][1]]
			heapq.heappop(q)
	return res
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	print(*solve(n, a, x))


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial, sqrt
from collections import defaultdict, Counter, OrderedDict, deque
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def bi(x):
	(l, h) = (0, n - 1)
	res = n
	while l <= h:
		m = l + h >> 1
		if pref_m[m] >= x:
			res = m
			h = m - 1
		else:
			l = m + 1
	return -1 if res == n else res
for _ in range(I()):
	(n, m) = tup()
	a = lint()
	b = lint()
	pre = [a[i] for i in range(n)]
	pref_m = [a[i] for i in range(n)]
	for i in range(1, n):
		pre[i] += pre[i - 1]
		pref_m[i] = max(pre[i], pref_m[i - 1])
	if pre[-1] <= 0:
		for x in b:
			print(bi(x), end=' ')
	else:
		ma = max(pre)
		for x in b:
			t = max(0, (x - ma + pre[-1] - 1) // pre[-1])
			print(t * n + bi(x - t * pre[-1]), end=' ')
	print()
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


import sys
from sys import stdin
import bisect
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	xlis = list(map(int, stdin.readline().split()))
	s = 0
	inds = []
	sums = []
	for i in range(n):
		s += a[i]
		if len(inds) == 0:
			if s > 0:
				inds.append(i)
				sums.append(s)
		elif sums[-1] < s:
			inds.append(i)
			sums.append(s)
	ans = []
	if len(sums) == 0:
		print(*[-1 for i in range(m)])
		continue
	for x in xlis:
		if s <= 0:
			if sums[-1] < x:
				ans.append(-1)
			else:
				ans.append(inds[bisect.bisect_left(sums, x)])
		else:
			l = -1
			r = x + 1
			while r - l != 1:
				mid = (l + r) // 2
				if s * mid + sums[-1] >= x:
					r = mid
				else:
					l = mid
			nans = n * r
			rem = x - r * s
			ans.append(nans + inds[bisect.bisect_left(sums, rem)])
	print(*ans)


def findIncrementIndex(sumIncrementIndices, x):
	l = 0
	r = len(sumIncrementIndices)
	while l < r:
		m = (l + r) // 2
		if sumIncrementIndices[m][0] < x:
			l = m + 1
		else:
			r = m
	return sumIncrementIndices[r][1]

def solve(A, n, X, m):
	runningSum = 0
	lastIncrementedSum = 0
	sumIncrementIndices = []
	for i in range(n):
		runningSum += A[i]
		if runningSum > lastIncrementedSum:
			sumIncrementIndices.append((runningSum, i))
			lastIncrementedSum = runningSum
	result = []
	totalSum = runningSum
	for i in range(m):
		x = X[i]
		seconds = 0
		if x > lastIncrementedSum:
			if totalSum <= 0:
				result.append(-1)
				continue
			roundsCount = (x - lastIncrementedSum + totalSum - 1) // totalSum
			seconds = roundsCount * n
			x -= roundsCount * totalSum
		seconds += findIncrementIndex(sumIncrementIndices, x)
		result.append(seconds)
	return result
t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	X = list(map(int, input().split()))
	result = solve(A, n, X, m)
	print(*result)


from bisect import *
import math
a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	z = list(map(int, input().split()))
	x = list(map(int, input().split()))
	for i in range(1, len(z)):
		z[i] += z[i - 1]
	maxa = []
	for i in range(len(z)):
		if i == 0:
			maxa.append(z[0])
		else:
			maxa.append(max(maxa[-1], z[i]))
	for i in range(len(x)):
		r = bisect_left(maxa, x[i])
		if r == len(maxa) and z[-1] <= 0:
			print(-1, end=' ')
		elif r < len(maxa):
			print(r, end=' ')
		else:
			left = x[i] - maxa[-1]
			rounds = math.ceil(left / z[-1])
			actual = x[i] - rounds * z[-1]
			r = bisect_left(maxa, actual)
			total = rounds * len(z) - 1
			print(total + r + 1, end=' ')
	print(' ')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd
from bisect import bisect_left
for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	q = list(map(int, input().split()))
	b = sum(l)
	d = dd(list)
	a = 0
	x = 0
	c = 0
	for i in range(n):
		c += l[i]
		d[c].append(i)
		if c > a:
			a = c
			x = i
	l1 = []
	for i in d:
		l1.append(i)
	l1.sort()
	y = n
	l2 = [n] * len(l1)
	for i in range(len(l1) - 1, -1, -1):
		for j in d[l1[i]]:
			y = min(y, j)
		l2[i] = y
	ans = [-1] * m
	for i in range(m):
		if a < q[i] and b <= 0:
			continue
		if q[i] <= a:
			ans[i] = l2[bisect_left(l1, q[i])]
		else:
			c = q[i] - a
			e = c // b
			f = c % b
			if not f:
				ans[i] = e * n + x
			else:
				p = b * (e + 1)
				r = q[i] - p
				z = bisect_left(l1, r)
				if z != len(l1):
					x1 = (e + 1) * n + l2[z]
				else:
					x1 = 10 ** 18
				e = q[i] // b
				f = q[i] % b
				if not f:
					ans[i] = e * n - 1
				else:
					z = bisect_left(l1, f)
					ans[i] = min(x1, e * n + l2[z])
				p = b * (e - 1)
				r = q[i] - p
				z = bisect_left(l1, r)
				if z != len(l1):
					x1 = (e - 1) * n + l2[z]
				else:
					x1 = 10 ** 18
				while ans[i] > x1 and q[i] - b * (e - 1) <= a:
					e -= 1
					p = b * (e - 1)
					r = q[i] - p
					z = bisect_left(l1, r)
					if z != len(l1):
						x1 = (e - 1) * n + l2[z]
				ans[i] = min(ans[i], x1)
	print(*ans)


import sys, os, io
from sys import stdin
from bisect import bisect_left, bisect_right
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
si = lambda : input()
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
t = 1
t = int(input())

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1
for _ in range(t):
	(n, m) = li()
	a = li()
	xl = li()
	mx = []
	curSum = 0
	mxind = []
	for i in range(n):
		curSum += a[i]
		if mx == [] or mx[-1] < curSum:
			mx.append(curSum)
			mxind.append(i)
	res = []
	for x in xl:
		if x > mx[-1] and curSum <= 0:
			res.append(-1)
		else:
			temp = 0
			if x > mx[-1]:
				dif = x - mx[-1]
				temp = divideCeil(dif, curSum)
			toFind = x - temp * curSum
			ind = bisect_left(mx, toFind)
			res.append(temp * n + mxind[ind])
	print(*res)


from math import ceil
from bisect import bisect_left

def find():
	(n, m) = map(int, input().split())
	sum_a = 0
	pref = {}
	pref_s = [0]
	ind = 0
	for j in input().split():
		sum_a += int(j)
		if sum_a not in pref:
			pref[sum_a] = ind
		if sum_a > pref_s[-1]:
			pref_s.append(sum_a)
		ind += 1
	for j in input().split():
		j = int(j)
		ans = 0
		if j <= pref_s[-1]:
			my_pref = j
		elif sum_a <= 0:
			print(-1, end=' ')
			continue
		else:
			tmp = ceil((j - pref_s[-1]) / sum_a)
			my_pref = max(0, j - tmp * sum_a)
			ans += tmp * n
		print(ans + pref[pref_s[bisect_left(pref_s, my_pref, lo=1)]], end=' ')
	print()
for i in range(int(input())):
	find()


import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq
INF = 10 ** 20
MOD = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def flush():
	return sys.stdout.flush()

def nicf():
	return int(sys.stdin.readline())

def nscf():
	return map(int, sys.stdin.readline().split())

def nacf():
	return list(map(int, sys.stdin.readline().split()))

def na1cf():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def solve():
	(n, m) = ns()
	ta = na()
	x = na()
	a = []
	mx = -1
	total = 0
	for (i, ai) in enumerate(ta):
		total += ai
		mx = max(mx, total)
		a.append([total, i])
	a.sort()
	aval = [a0 for (a0, a1) in a]
	aidx = [a1 for (a0, a1) in a]
	mnidx = [-1] * n
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			mnidx[i] = aidx[i]
		else:
			mnidx[i] = min(mnidx[i + 1], aidx[i])
	res = []
	for xi in x:
		if xi <= mx:
			idx = bisect.bisect_left(aval, xi)
			res.append(mnidx[idx])
			continue
		if total <= 0:
			res.append(-1)
			continue
		cycle = (xi - mx - 1) // total + 1
		txi = xi - cycle * total
		idx = bisect.bisect_left(aval, txi)
		res.append(cycle * n + mnidx[idx])
	print(*res)

def main():
	t = ni()
	for ti in range(t):
		solve()
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	pre = [0] * (n + 1)
	s = 0
	for i in range(1, n + 1):
		pre[i] = pre[i - 1] + l[i - 1]
		s += l[i - 1]
	for i in range(1, n + 1):
		pre[i] = max(pre[i], pre[i - 1])
	ma = max(pre)
	x = list(map(int, input().split()))
	ans = []
	for i in range(m):
		su = x[i]
		if s <= 0:
			d = binarySearchCount(pre, len(pre), su)
			if d == len(pre):
				ans.append(-1)
			else:
				ans.append(d - 1)
		else:
			t = su
			t -= ma
			t = max(t, 0)
			ans1 = int(math.ceil(t / s))
			su -= s * ans1
			d = binarySearchCount(pre, len(pre), su)
			if d == len(pre):
				ans.append(-1)
			else:
				ans.append(d + ans1 * n - 1)
	print(*ans)


import math
from bisect import bisect_left, bisect_right
import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
T = int(input())
for _ in range(T):
	(N, M) = get_ints()
	A = get_ints()
	X = get_ints()
	last_val = 0
	presum = []
	index = []
	sort_presum = []
	max_val = float('-inf')
	for i in range(N):
		if not presum or presum[-1] < last_val + A[i]:
			presum.append(last_val + A[i])
			index.append(i)
		last_val += A[i]
	vis = {}
	q_idx = 0
	p_idx = 0
	for q_idx in range(M):
		val = X[q_idx]
		if presum[-1] < val and last_val <= 0:
			vis[q_idx] = -1
			continue
		if presum[-1] < val:
			t = math.ceil((val - presum[-1]) / last_val)
		else:
			t = 0
		val -= t * last_val
		i = bisect_left(presum, val)
		vis[q_idx] = t * N + index[i]
	ans = [str(vis[i]) for i in range(M)]
	print(' '.join(ans))


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		(n, m) = [int(s) for s in input().split()]
		l = [int(s) for s in input().split()]
		q = [int(s) for s in input().split()]
		s = sum(l)
		ma = -10 ** 9 - 7
		curr = 0
		for i in range(n):
			curr += l[i]
			ma = max(curr, ma)
		ans = [-1] * m
		qs = []
		for i in range(m):
			if q[i] > ma:
				if s <= 0:
					continue
				else:
					w = (q[i] - ma) // s * s
					ans[i] = n * ((q[i] - ma) // s)
					if w + ma < q[i]:
						w += s
						ans[i] += n
					qs.append([q[i] - w, i])
			else:
				ans[i] = 0
				qs.append([q[i], i])
		qs.sort()
		j = 0
		curr = 0
		for i in range(n):
			curr += l[i]
			while j < len(qs) and qs[j][0] <= curr:
				ans[qs[j][1]] += i
				j += 1
		print(*ans)
main()


import sys
import math
from collections import defaultdict, Counter, deque
import bisect
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	pre = [0] * n
	pre[0] = a[0]
	cur = a[0]
	for j in range(1, n):
		cur += a[j]
		pre[j] = max(cur, pre[j - 1])
	ans = [0] * m
	for j in range(m):
		if cur <= 0:
			if pre[-1] < x[j]:
				ans[j] = -1
			else:
				ans[j] = bisect.bisect_left(pre, x[j])
		else:
			if pre[-1] < x[j]:
				req = x[j] - pre[-1]
				d = req // cur
				if req % cur:
					d += 1
				x[j] -= d * cur
				ans[j] = n * d
			ans[j] += bisect.bisect_left(pre, x[j])
	print(*ans)


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def dadd(d, p, val):
	if p in d:
		d[p].append(val)
	else:
		d[p] = [val]

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
uu = t
while t > 0:
	t -= 1
	(n, q) = mi()
	a = li()
	pre = [0]
	m = []
	for i in a:
		pre.append(pre[-1] + i)
	pre.pop(0)
	m = [pre[0]]
	for i in range(1, n):
		m.append(max(m[-1], pre[i]))
	p = li()
	for i in range(q):
		c = pre[-1]
		x = p[i]
		if c <= 0 and m[-1] < x:
			print(-1, end=' ')
			continue
		l = cur = 0
		r = x
		while l <= r:
			mid = (l + r) // 2
			if mid * c < x - m[-1]:
				l = mid + 1
			else:
				cur = mid
				r = mid - 1
		ans = cur * n
		x -= cur * c
		l = cur = 0
		r = n - 1
		while l <= r:
			mid = (l + r) // 2
			if m[mid] < x:
				l = mid + 1
			else:
				cur = mid
				r = mid - 1
		ans += cur + 1
		print(ans - 1, end=' ')
	print()


def findIndexGE(prefixSumsMax, startSum, query):
	n = len(prefixSumsMax)
	b = n
	i = -1
	while b > 0:
		while i + b < n and startSum + prefixSumsMax[i + b] < query:
			i += b
		b //= 2
	i += 1
	return i

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, m) = readIntArr()
		arr = readIntArr()
		queries = readIntArr()
		prefixSums = arr.copy()
		for i in range(1, n):
			prefixSums[i] += prefixSums[i - 1]
		maxP = max(prefixSums)
		prefixSumsMax = prefixSums.copy()
		for i in range(1, n):
			prefixSumsMax[i] = max(prefixSumsMax[i - 1], prefixSums[i])
		ans = []
		for q in queries:
			if prefixSums[n - 1] <= 0:
				if q > maxP:
					ans.append(-1)
				else:
					ans.append(findIndexGE(prefixSumsMax, 0, q))
			else:
				nCycles = -1
				b = 10 ** 9
				while b > 0:
					while prefixSums[n - 1] * (nCycles + b) + maxP < q:
						nCycles += b
					b //= 2
				nCycles += 1
				startSum = prefixSums[n - 1] * nCycles
				lastCycleIdx = findIndexGE(prefixSumsMax, startSum, q)
				ans.append(nCycles * n + lastCycleIdx)
		allans.append(ans)
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


from bisect import *
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	xs = list(map(int, input().split()))
	pre = []
	for i in range(n):
		try:
			pre.append((pre[-1][0] + arr[i], i))
		except:
			pre.append((arr[i], i))
	cy = pre[-1][0]
	pp = []
	m = pre[0][0]
	idx = 0
	for (x, y) in pre:
		if x > m:
			m = x
			idx = y
		pp.append((m, idx))
	pp.sort(key=lambda x: x[0])
	pr = []
	for i in pp:
		pr.append(i[0])
	m = pr[-1]
	out = []
	for i in xs:
		if i <= m:
			idx = bisect_left(pr, i)
			out.append(pp[idx][1])
		elif cy > 0:
			r = math.ceil((i - m) / cy)
			t = n * r + pp[bisect_left(pr, i - cy * r)][1]
			out.append(t)
		else:
			out.append(-1)
	print(*out)


import sys
input = sys.stdin.readline
from collections import Counter
import bisect
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(item) for item in input().split()]
	x = [int(item) for item in input().split()]
	cumsum = [0]
	cummax = [0]
	for item in a:
		cumsum.append(cumsum[-1] + item)
		cummax.append(max(cummax[-1], cumsum[-1]))
	diff = cumsum[-1]
	ans = []
	for item in x:
		ret = 0
		if diff <= 0 and item > cummax[-1]:
			ans.append(-1)
			continue
		if item > cummax[-1]:
			loop = (item - cummax[-1] + diff - 1) // diff
			ret += loop * n
			item -= diff * loop
		ret += bisect.bisect_left(cummax, item) - 1
		ans.append(ret)
	print(*ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
from bisect import bisect_left
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	p = [0] * (n + 1)
	M = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = p[i] + a[i]
		M[i + 1] = max(M[i], p[i + 1])
	s = p[-1]
	ans = []
	for x in map(int, input().split()):
		r = 0
		if s > 0:
			t = max((x - M[-1] + s - 1) // s, 0)
			r += t * n
			x -= t * s
		if x > M[-1]:
			ans.append('-1')
		else:
			pos = bisect_left(M, x)
			ans.append(str(r + pos - 1))
	print(' '.join(ans))
endtime = time.time()


from math import log2

def found(a, value, m):
	mid = len(a) // 2
	low = 0
	high = len(a) - 1
	while low < high:
		if value <= a[mid][0]:
			high = mid
		else:
			low = mid + 1
		mid = (low + high) // 2
	if a[mid][0] >= value:
		return m[mid]
	else:
		return m[mid]
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	q = list(map(int, input().split()))
	circle = sum(a)
	s = [[0, 0]]
	for i in range(len(a)):
		s.append([a[i] + s[-1][0], i + 1])
	max_circle = max(s)[0]
	s.sort()
	mini = s[-1][1]
	mini_lol = [0 for i in range(len(s))]
	for i in range(len(mini_lol) - 1, -1, -1):
		mini = min(mini, s[i][1])
		mini_lol[i] = mini
	answer = []
	for x in q:
		if x > max_circle and circle <= 0:
			ans = -1
		elif x <= max_circle:
			ans = found(s, x, mini_lol) - 1
		else:
			delta = x - (x - max_circle) // circle * circle
			ans = len(a) * ((x - max_circle) // circle)
			if delta > max_circle:
				delta -= circle
				ans += len(a)
			x = delta
			ans += found(s, x, mini_lol) - 1
		answer.append(ans)
	print(*answer)


from bisect import *
I = lambda : map(int, input().split())
for _ in range(*I()):
	(n, m) = I()
	p = [0]
	M = [0]
	for v in I():
		p += (p[-1] + v,)
		M += (max(M[-1], p[-1]),)
	s = p[-1]
	a = []
	for x in map(int, input().split()):
		r = 0
		if s > 0:
			t = max((x - M[-1] + s - 1) // s, 0)
			r = t * n
			x -= t * s
		a += ([str(r + bisect_left(M, x) - 1), '-1'][x > M[-1]],)
	print(*a)


import bisect
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	asum = sum(a)
	t = 0
	p = []
	for (i, x) in enumerate(a):
		t += x
		if len(p) == 0 or p[-1][0] < t:
			p.append((t, i))
	pp = [y[0] for y in p]
	ans = []
	for x in b:
		r = 0
		if p[-1][0] < x:
			if asum <= 0:
				ans.append(-1)
				continue
			r = (x - p[-1][0]) // asum
			if (x - p[-1][0]) % asum > 0:
				r += 1
			x -= r * asum
		i = bisect.bisect_left(pp, x)
		ans.append(p[i][1] + r * n)
	print(' '.join(map(str, ans)))


import sys
input = sys.stdin.readline
from bisect import bisect_left

def getans(a, x, n, ma, s, ss, ssi):
	p = ma
	if s > 0:
		cnt = 0
		if x <= ma:
			return ssi[bisect_left(ss, x)]
		if x > ma:
			cnt = (x - ma) // s
		p += cnt * s
		while 1:
			if x <= p:
				return n * cnt + ssi[bisect_left(ss, x - cnt * s)]
			p += s
			cnt += 1
	if s <= 0:
		if x <= p:
			return ssi[bisect_left(ss, x)]
		return -1
for _ in range(int(input())):
	(n, m) = [*map(int, input().split())]
	a = [*map(int, input().split())]
	b = [*map(int, input().split())]
	s = a[0]
	ss = [a[0]]
	ssi = [0]
	for i in range(1, n):
		s += a[i]
		if s > ss[-1]:
			ss.append(s)
			ssi.append(i)
	ma = ss[-1]
	for i in range(m):
		print(getans(a, b[i], n, ma, s, ss, ssi), end=' ')


from math import ceil

def find():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	sum_a = 0
	pref = {}
	pref_s = [0]
	for j in range(n):
		sum_a += a[j]
		if sum_a not in pref:
			pref[sum_a] = j
		if a[j] > 0 and sum_a > pref_s[-1]:
			pref_s.append(sum_a)
	for j in x:
		ans = 0
		if j <= pref_s[-1]:
			my_pref = j
		elif sum_a <= 0:
			print(-1, end=' ')
			continue
		else:
			tmp = ceil((j - pref_s[-1]) / sum_a)
			my_pref = max(0, j - tmp * sum_a)
			ans += tmp * n
		ind_min = 1
		ind_max = len(pref_s) - 1
		while ind_min != ind_max:
			ind_new = (ind_min + ind_max) // 2
			if pref_s[ind_new] < my_pref:
				ind_min = ind_new + 1
			else:
				ind_max = ind_new
		print(ans + pref[pref_s[ind_max]], end=' ')
	print()
for i in range(int(input())):
	find()


from bisect import *
from random import *
from itertools import *
import sys
read = sys.stdin.readline
write = lambda x, end='\n': sys.stdout.write(x + end)

def naive(a, q, t, m):
	if t <= 0 and m < q:
		return -1
	x = 0
	for i in count():
		x += a[i % len(a)]
		if x >= q:
			return i

def g(a, q, t, m):
	return bisect_left(d, q)

def f(a, q, t, m):
	if t <= 0 and m < q:
		return -1
	elif q <= m:
		return g(a, q, t, m)
	z = 0 if t == 0 else max(0, (q - m) // t)
	return z * len(a) + g(a, q - t * z, t, m)
for _ in range(int(read())):
	(n, m) = map(int, read().split())
	a = list(map(int, read().split()))
	c = list(accumulate(a))
	d = list(accumulate(list(accumulate(a + a)), max))
	m = max(c)
	t = sum(a)
	res = []
	z = []
	for q in map(int, read().split()):
		z.append(f(a, q, t, m))
	print(*z)


import bisect
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	pre = [0] * n
	pre[0] = a[0]
	cur = a[0]
	for j in range(1, n):
		cur += a[j]
		pre[j] = max(cur, pre[j - 1])
	ans = [0] * m
	for j in range(m):
		if cur <= 0:
			if pre[-1] < x[j]:
				ans[j] = -1
			else:
				ans[j] = bisect.bisect_left(pre, x[j])
		else:
			if pre[-1] < x[j]:
				req = x[j] - pre[-1]
				d = req // cur
				if req % cur:
					d += 1
				x[j] -= d * cur
				ans[j] = n * d
			ans[j] += bisect.bisect_left(pre, x[j])
	print(*ans)


from collections import Counter
from bisect import bisect_right, bisect_left
from math import ceil

def solve(b, total, x, n):
	if len(b) == 0:
		return -1
	if x > b[-1] and total <= 0:
		return -1
	if x <= b[-1]:
		return bisect_left(b, x)
	c = ceil((x - b[-1]) / total)
	idx = bisect_left(b, x - c * total)
	return c * n + idx
t = int(input())
for i in range(t):
	(n, m) = tuple(map(int, input().split()))
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	total = sum(a)
	b = [0]
	c = 0
	for e in a:
		c += e
		b.append(max(c, b[-1]))
	b = b[1:]
	for xi in x:
		print(solve(b, total, xi, n), end=' ')
	print()


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().split(' ')

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def prefix_max(a):
	p = [-float('inf')]
	for x in a:
		p.append(max(p[-1], x))
	return p

def ceil_div(a, b):
	return a // b + int(a % b != 0)

def solve_a():
	n = get_int()
	a = get_ints()
	k = 0
	for i in range(n - 1):
		A = max(a[i], a[i + 1])
		B = min(a[i], a[i + 1])
		while 2 * B < A:
			k += 1
			B *= 2
	return k

def solve_b():
	n = get_int()
	a = get_ints()
	rems = [x % 3 for x in a]
	count_rems = [rems.count(i) for i in range(3)]
	k = 0
	for repeat in range(2):
		for i in range(3):
			if count_rems[i] > n // 3:
				k += count_rems[i] - n // 3
				count_rems[(i + 1) % 3] += count_rems[i] - n // 3
				count_rems[i] = n // 3
	return k

def solve_c():
	cubes = set()
	i = 1
	while i ** 3 < 10 ** 12 + 1:
		cubes.add(i ** 3)
		i += 1

	def solve():
		x = get_int()
		j = 1
		while j ** 3 <= x:
			if x - j ** 3 in cubes:
				return 'YES'
			j += 1
		return 'NO'
	t = get_int()
	for _ in range(t):
		print(solve())

def solve_d():
	n = get_int()
	p = get_ints()
	dp = [-1] * n
	for i in range(n, 0, -1):
		X = p.index(i)
		m = -1
		for j in range(X, n):
			if dp[j] > -1:
				m = max(m, dp[j])
				break
		for j in range(X, -1, -1):
			if dp[j] > -1:
				m = max(m, dp[j])
				break
		dp[X] = m + 1
	res = {}
	return dp

def solve_e():
	n = get_int()
	a = get_ints()
	a_uniq = list(set(a))
	a_uniq.sort()
	a_count = Counter(a)

	def good(k):
		x = a_uniq[k]
		for i in range(len(a_uniq)):
			if x >= a_uniq[i]:
				x += a_uniq[i] * (a_count[a_uniq[i]] - int(i == k))
			else:
				return False
		return True
	L = -1
	R = len(a_uniq) - 1
	bs = binary_search(good, L, R, right_true=True)
	u = a_uniq[bs]
	res = []
	for i in range(n):
		if a[i] >= u:
			res.append(i + 1)
	return res

def solve_f():
	n = get_int()
	a = get_ints()
	C = Counter(a)
	candidates = set(C.values())
	S = float('inf')
	for cand in candidates:
		tmp = 0
		for k in C:
			if C[k] < cand:
				tmp += C[k]
			elif C[k] > cand:
				tmp += C[k] - cand
		S = min(S, tmp)
	return S

def solve_g():
	(n, m) = get_ints()
	a = get_ints()
	x = get_ints()
	S = sum(a)
	p = prefix_sums(a)
	pm = prefix_max(p)[2:]

	def respond(y):
		if S <= 0 and pm[-1] < y:
			return -1
		if S > 0:
			rots = max(0, ceil_div(y - pm[-1], S))
		else:
			rots = 0
		y -= rots * S
		if y == 0:
			z = -1
		else:
			z = bisect.bisect_left(pm, y)
		return rots * n + z
	response = [respond(y) for y in x]
	return response
t = get_int()
for _ in range(t):
	print(*solve_g())


import bisect

class IntervalTree:

	@staticmethod
	def get_depth(n):
		depth = 0
		i = 1
		while i < n:
			depth += 1
			i <<= 1
		return depth

	def __init__(self, n):
		self.n = n
		self.depth = IntervalTree.get_depth(n)
		self.top = 1 << self.depth
		self.v = []
		for i in range(self.top + self.n):
			self.v.append(None)

	def add(self, pos, value):
		assert pos < self.n
		idx = 1
		mask = 1 << self.depth - 1
		while idx < len(self.v):
			if self.v[idx] is None or self.v[idx] < value:
				self.v[idx] = value
			idx <<= 1
			if pos & mask != 0:
				idx += 1
			mask >>= 1

	def get_impl(self, idx, l, r, v):
		if r - l == 1:
			return l
		idx <<= 1
		m = (l + r) // 2
		if self.v[idx] >= v:
			return self.get_impl(idx, l, m, v)
		else:
			return self.get_impl(idx + 1, m, r, v)

	def get(self, v):
		if self.v[1] < v:
			return self.n
		return self.get_impl(1, 0, self.top, v)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) for i in input().split()]
	x = [int(i) for i in input().split()]
	b = []
	if n == 1:
		for x_i in x:
			if a[0] <= 0:
				b.append(-1)
			else:
				b.append((x_i + a[0] - 1) // a[0] - 1)
	else:
		sum_a = sum(a)
		s = 0
		it = IntervalTree(n)
		for i in range(n):
			s += a[i]
			it.add(i, s)
		max_s_i = it.v[1]
		for x_i in x:
			pos = it.get(x_i)
			if pos < n:
				b.append(pos)
				continue
			if sum_a <= 0:
				b.append(-1)
				continue
			b_i = (x_i - max_s_i) // sum_a
			x_i -= sum_a * b_i
			b_i *= n
			while True:
				pos = it.get(x_i)
				if pos == n:
					b_i += n
					x_i -= sum_a
				else:
					b_i += pos
					break
			b.append(b_i)
	print(' '.join([str(i) for i in b]))


from bisect import bisect_left
import math

def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		(n, m) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		x = list(map(int, input().split(' ')))
		sums = []
		cur = 0
		max_sum = float('-inf')
		for val in a:
			cur += val
			sums.append(cur)
			max_sum = max(max_sum, cur)
		cycle_sum = sums[-1]
		sums = [(val, i) for (i, val) in enumerate(sums)]
		sums.sort()
		(sorted_sums, indices) = ([], [])
		min_idx = float('inf')
		for (cur_sum, idx) in sums:
			sorted_sums.append(cur_sum)
		for (cur_sum, idx) in reversed(sums):
			min_idx = min(min_idx, idx)
			indices.append(min_idx)
		indices = indices[::-1]
		query_answers = []
		for q in x:
			if q <= max_sum:
				search_idx = bisect_left(sorted_sums, q)
				query_answers.append(indices[search_idx])
			elif cycle_sum <= 0:
				query_answers.append(-1)
			else:
				cycles_required = int(math.ceil((q - max_sum) / cycle_sum))
				search_idx = bisect_left(sorted_sums, q - cycles_required * cycle_sum)
				query_answers.append(indices[search_idx] + cycles_required * n)
		ans_list.append(' '.join(map(str, query_answers)))
	print('\n'.join(ans_list))
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac
for xyz in range(0, int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	pre = [0]
	reqpre = [0]
	for i in l:
		pre.append(pre[-1] + i)
		reqpre.append(max(reqpre[-1], pre[-1]))
	x = list(map(int, input().split()))
	ans = []
	for i in x:
		ca = 0
		if 0 >= pre[-1] and i > reqpre[-1]:
			ans.append(-1)
		else:
			if pre[-1] != 0 and reqpre[-1] < i:
				cycles = max(0, (i - reqpre[-1] + pre[-1] - 1) // pre[-1])
			else:
				cycles = 0
			ca += cycles * n
			i -= cycles * pre[-1]
			pos = bisect.bisect_left(reqpre, i)
			ca += pos - 1
			ans.append(ca)
	print(*ans)


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median, mean
from math import gcd, sqrt, floor, factorial, ceil, log2, log10, log
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10 ** 8)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange
from time import time

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def get_list():
	return list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]

def p(a):
	if type(a) == str:
		print(a + '\n')
	else:
		print(str(a) + '\n')

def ps(a):
	if type(a) == str:
		print(a)
	else:
		print(str(a))

def kth_no_not_div_by_n(n, k):
	return k + (k - 1) // (n - 1)
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'
t = int(input())
for i in range(t):
	(n, m) = get_map()
	a = get_list()
	x = get_list()
	suma = sum(a)
	prefix = [0 for i in range(n)]
	maxa = [0 for i in range(n)]
	for i in range(n):
		prefix[i] = a[i]
		maxa[i] = prefix[i]
		if i:
			prefix[i] += prefix[i - 1]
			maxa[i] = max(prefix[i], maxa[i - 1])
	if suma <= 0:
		for i in x:
			indexa = bisect_left(maxa, i)
			if indexa == n:
				print(-1, end=' ')
			else:
				print(indexa, end=' ')
	else:
		for i in x:
			count = 0
			if i > maxa[-1]:
				if i % suma == 0:
					count = ceil((i - maxa[-1]) / suma)
					i = i - count * suma
				else:
					count = ceil((i - maxa[-1]) / suma)
					i = i - count * suma
			indexa = bisect_left(maxa, i)
			print(count * n + indexa, end=' ')
	print('')


import math
import sys
import collections
import bisect
import heapq
testcases = int(sys.stdin.readline())
for _ in range(testcases):
	arr = list(map(int, sys.stdin.readline().strip().split()))
	n = arr[0]
	m = arr[1]
	ns = list(map(int, sys.stdin.readline().strip().split()))
	ms = list(map(int, sys.stdin.readline().strip().split()))
	subs = [0] * n
	mx = 0
	s = 0
	improves = []
	imp = []
	for (i, j) in enumerate(ns):
		s += j
		subs[i] = s
		if s > mx:
			mx = s
			improves.append((s, i))
			imp.append(s)
	for m in ms:
		if subs[-1] <= 0 and m > mx:
			print(-1, end=' ')
			continue
		else:
			res = 0
			x = m - mx
			if x > 0:
				res = math.ceil(x / subs[-1]) * len(ns)
				m -= math.ceil(x / subs[-1]) * subs[-1]
			ind = bisect.bisect_left(imp, m)
			res += improves[ind][1]
			print(res, end=' ')
	print('')


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	(n, m) = RL()
	a = RLL()
	x = RLL()
	pre = 0
	stack = [[0, -1]]
	for (i, ch) in enumerate(a):
		pre += ch
		if pre <= stack[-1][0]:
			continue
		stack.append([pre, i])
	ans = A(m)
	for i in range(m):
		ind = bisect_left(stack, [x[i], -1])
		if ind >= len(stack):
			if pre <= 0:
				ans[i] = -1
			else:
				per = (x[i] - stack[-1][0] + pre - 1) // pre
				x[i] -= per * pre
				ind = bisect_left(stack, [x[i], -1])
				ans[i] = per * n + stack[ind][1]
		else:
			ans[i] = stack[ind][1]
	print(*ans)


import os
import sys
from bisect import bisect_left
from collections import Counter
from io import BytesIO, IOBase
from math import ceil

def f(n):
	return int(n) % 3

def main():
	from collections import Counter
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = [int(X) for X in input().split()]
		pre = [a[0]]
		tt = a[0]
		y = sum(a)
		for i in range(1, n):
			tt += a[i]
			pre.append(max(pre[-1], tt))
		mn = []
		qq = [int(X) for X in input().split()]
		for j in qq:
			if y <= 0:
				op = bisect_left(pre, j)
				mn.append(-1 if op == n else op)
			else:
				tmp = max(0, j - pre[-1])
				j -= ceil(tmp / y) * y
				op = bisect_left(pre, j)
				mn.append(op + n * ceil(tmp / y))
		print(*mn)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import bisect

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		x = list(map(int, input().split()))
		p = []
		pts = []
		M = 0
		d = {}
		suma = 0
		for i in range(n):
			suma += a[i]
			if suma > M:
				M = suma
				pts.append(M)
				d[M] = i
		for i in range(m):
			xi = x[i]
			if not pts:
				p.append(-1)
				continue
			if suma <= 0 or xi <= pts[-1]:
				if xi > pts[-1]:
					p.append(-1)
					continue
				else:
					idx = bisect.bisect_left(pts, xi)
					p.append(d[pts[idx]])
			else:
				laps = (xi - pts[-1]) // suma
				if (xi - pts[-1]) % suma:
					laps += 1
				xi -= laps * suma
				idx = bisect.bisect_left(pts, xi)
				p.append(d[pts[idx]] + n * laps)
		print(*p)
main()


from bisect import *
from math import ceil
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	prefMax = [a[0]] * n
	prefSum = [a[0]] * n
	for i in range(1, n):
		prefSum[i] = prefSum[i - 1] + a[i]
		prefMax[i] = max(prefMax[i - 1], prefSum[i])
	ans = []
	for tar in x:
		curr = -1
		if tar <= prefMax[-1]:
			curr = bisect_left(prefMax, tar)
		elif prefSum[-1] > 0:
			tot = ceil((tar - prefMax[-1]) / prefSum[-1])
			curr = tot * n + (bisect_left(prefMax, tar - tot * prefSum[-1]) if tar != tot * prefSum[-1] else -1)
		ans.append(curr)
	print(*ans)


from sys import stdin
from math import ceil
from bisect import bisect_left as bl
input = stdin.readline

def greater(num, arr):
	ind = bl(arr, num)
	return arr[ind]
for test in range(int(input())):
	(n, m) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	x = list(map(int, input().strip().split()))
	dct = {}
	s = 0
	ans = [-1] * m
	temp = 0
	for i in range(n):
		s += lst[i]
		temp = max(temp, s)
		try:
			dct[temp]
		except KeyError:
			dct.update({s: i})
	sum_lst = list(dct.keys())
	s_max = sum_lst[-1]
	if s_max > 0:
		for i in range(m):
			if x[i] <= s_max:
				num = greater(x[i], sum_lst)
				ans[i] = dct[num]
			elif s > 0:
				store = ceil((x[i] - s_max) / s)
				check = x[i] - store * s
				num = greater(check, sum_lst)
				ans[i] = dct[num] + store * n
	print(*ans)


from bisect import bisect_left
tc = int(input())
for _ in range(tc):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	Val = sum(a)
	process = []
	ret = []
	curr = 0
	index = {}
	for i in range(n):
		curr += a[i]
		if i == 0:
			process.append(curr)
			index[curr] = i
		elif curr > process[-1]:
			process.append(curr)
			index[curr] = i
	localBig = process[-1]
	for num in x:
		if localBig < num and Val <= 0:
			ret.append('-1')
			continue
		spins = 0
		if localBig < num:
			spins = (num - localBig + Val - 1) // Val
		num -= spins * Val
		pos = spins * n + index[process[bisect_left(process, num)]]
		ret.append(str(pos))
	print(' '.join(ret))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = [0] * 200001

def SieveOfEratosthenes(n=200000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	pre = []
	s = 0
	prev = 0
	for i in range(n):
		s += a[i]
		if s > prev:
			pre.append((s, i + 1))
			prev = s
	b = list(map(int, input().split()))
	for k in b:
		if k <= prev:
			(l, r) = (0, len(pre) - 1)
			res = 0
			while l <= r:
				mid = (l + r) // 2
				if pre[mid][0] >= k:
					res = pre[mid][1]
					r = mid - 1
				else:
					l = mid + 1
			print(res - 1)
			continue
		if s <= 0:
			print(-1)
			continue
		res = (k - prev) // s
		num = 0
		if (k - prev) % s == 0:
			num = prev
		else:
			res += 1
			num = k - res * s
		r1 = 0
		(l, r) = (0, len(pre) - 1)
		while l <= r:
			mid = (l + r) // 2
			if pre[mid][0] >= num:
				r1 = pre[mid][1]
				r = mid - 1
			else:
				l = mid + 1
		print(res * n + r1 - 1)


import bisect
N = int(input())

def solve(n, m, a, x):
	B = []
	mx_pref = -float('inf')
	s = 0
	for i in range(len(a)):
		s += a[i]
		mx_pref = max(mx_pref, s)
		B.append(mx_pref)
	ans = []
	for xi in x:
		if xi > mx_pref and s <= 0:
			ans.append(-1)
			continue
		if xi <= mx_pref:
			ans.append(bisect.bisect_left(B, xi))
		else:
			if (xi - mx_pref) % s == 0:
				k = (xi - mx_pref) // s - 1
			else:
				k = (xi - mx_pref) // s
			k += 1
			res = k * n - 1
			xi -= s * k
			if xi > 0:
				res += 1 + bisect.bisect_left(B, xi)
			ans.append(res)
	return ans
for _ in range(N):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	ans = solve(n, m, a, x)
	print(' '.join((str(x) for x in ans)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import inf, log2

class SegmentTree:

	def __init__(self, array, func=max):
		self.n = len(array)
		self.size = 2 ** (int(log2(self.n - 1)) + 1) if self.n != 1 else 1
		self.func = func
		self.default = 0 if self.func != min else inf
		self.data = [self.default] * (2 * self.size)
		self.process(array)

	def process(self, array):
		self.data[self.size:self.size + self.n] = array
		for i in range(self.size - 1, -1, -1):
			self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])

	def query(self, alpha, omega):
		if alpha == omega:
			return self.data[alpha + self.size]
		res = self.default
		alpha += self.size
		omega += self.size + 1
		while alpha < omega:
			if alpha & 1:
				res = self.func(res, self.data[alpha])
				alpha += 1
			if omega & 1:
				omega -= 1
				res = self.func(res, self.data[omega])
			alpha >>= 1
			omega >>= 1
		return res

	def update(self, index, value):
		index += self.size
		self.data[index] = value
		index >>= 1
		while index:
			self.data[index] = self.func(self.data[2 * index], self.data[2 * index + 1])
			index >>= 1
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

class Node:

	def __init__(self, v):
		self.value = v
		self.left = None
		self.right = None
for _ in range(int(input()) if True else 1):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mx = max(a)
	sm = sum(a)
	vals = []
	ans = a[0]
	vals += [ans]
	for i in range(1, n):
		ans += a[i]
		vals += [max(ans, vals[-1])]
	ans = []
	for x in b:
		if sm <= 0 and x > vals[-1]:
			ans += [-1]
			continue
		rotations = 0
		if sm > 0:
			rotations = max(int((x - vals[-1]) / sm) - 2, 0) if sm else 0
		(alpha, omega) = (0, n - 1)
		if sm > 0:
			x -= rotations * sm
			while x > vals[-1]:
				rotations += 1
				x -= sm
		else:
			rotations = 0
		while alpha < omega:
			mid = (alpha + omega) // 2
			if vals[mid] >= x:
				omega = mid
			else:
				alpha = mid + 1
		ans += [rotations * n + alpha]
	print(*ans)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from math import ceil
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	max_cycle_sum = -float('inf')
	cycle_sum = 0
	pos_max_cycle_sum = []
	for i in range(n):
		cycle_sum += a[i]
		max_cycle_sum = max(cycle_sum, max_cycle_sum)
		pos_max_cycle_sum.append(max_cycle_sum)
	for i in range(m):
		if max_cycle_sum >= x[i]:
			ans = bisect_left(pos_max_cycle_sum, x[i])
			print(ans, end=' ')
			continue
		elif cycle_sum <= 0:
			print(-1, end=' ')
			continue
		else:
			cycles_completed = ceil((x[i] - max_cycle_sum) / cycle_sum)
			ans = n * cycles_completed
			remaining = x[i] - cycles_completed * cycle_sum
			partial = bisect_left(pos_max_cycle_sum, remaining)
			ans += partial
			print(ans, end=' ')
	print()


from math import ceil

def bina(a):
	global array
	(low, high) = (0, len(array))
	while low < high:
		mid = low + (high - low) // 2
		if array[mid] >= a:
			high = mid
		else:
			low = mid + 1
	return high
for _ in range(int(input())):
	global array
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	mx = float('-inf')
	s = 0
	array = []
	for i in a:
		s += i
		mx = max(mx, s)
		array.append(mx)
	for i in range(m):
		x = b[i]
		if s <= 0:
			if x > mx:
				print(-1, end=' ')
			else:
				print(bina(x), end=' ')
		else:
			sub = max(0, ceil((x - mx) / s))
			print(n * sub + bina(x - s * sub), end=' ')
	print()


import bisect
from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	ops = [int(i) for i in input().split()]
	prefix_sum = [0 for i in range(n)]
	prefix_sum[0] = arr[0]
	for i in range(1, n):
		prefix_sum[i] = prefix_sum[i - 1] + arr[i]
	prefix_pos = []
	prefix_min_index = defaultdict(int)
	for i in range(n):
		if prefix_sum[i] > 0:
			prefix_pos.append((prefix_sum[i], i))
	prefix_pos.sort()
	for i in range(len(prefix_pos) - 1, -1, -1):
		if i < len(prefix_pos) - 1:
			prefix_min_index[prefix_pos[i][0]] = min(prefix_pos[i][1], prefix_min_index[prefix_pos[i + 1][0]])
		else:
			prefix_min_index[prefix_pos[i][0]] = prefix_pos[i][1]
	ans = []
	for i in range(m):
		tar = ops[i]
		if len(prefix_pos) <= 0:
			ans.append(-1)
			continue
		need = tar - prefix_pos[-1][0]
		if need <= 0:
			res = bisect.bisect_left(prefix_pos, (tar, 0))
			amount = prefix_pos[res][0]
			ans.append(prefix_min_index[amount])
		elif prefix_sum[-1] <= 0:
			ans.append(-1)
			continue
		else:
			times = need // prefix_sum[-1]
			if need % prefix_sum[-1] != 0:
				times += 1
			need = tar - times * prefix_sum[-1]
			res = bisect.bisect_left(prefix_pos, (need, 0))
			amount = prefix_pos[res][0]
			cost = times * n
			ans.append(cost + prefix_min_index[amount])
	print(' '.join((str(i) for i in ans)))


import sys
max_int = 2147483648
min_int = -max_int
t = int(input())
for _t in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	a = map(int, sys.stdin.readline().split())
	x = map(int, sys.stdin.readline().split())
	mx = 0
	s = 0
	maxs = []
	for (i, aa) in enumerate(a):
		s += aa
		if s > mx:
			mx = s
			maxs.append((s, i))
	full = s

	def search(v):
		l = -1
		r = len(maxs) - 1
		while r - l > 1:
			m = (r + l) // 2
			if maxs[m][0] >= v:
				r = m
			else:
				l = m
		return maxs[r][1]
	out = []
	for xx in x:
		tmp = 0
		if not maxs:
			out.append(-1)
			continue
		elif xx > maxs[-1][0]:
			if full > 0:
				tmp = (xx - maxs[-1][0] - 1) // full + 1
				xx -= full * tmp
				tmp *= n
			else:
				out.append(-1)
				continue
		out.append(tmp + search(xx))
	print(' '.join(map(str, out)))


from collections import defaultdict
from itertools import accumulate
import sys
import bisect
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
for CASES in range(int(input())):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	S = [0]
	for a in A:
		S.append(S[-1] + a)
	S1 = S.copy()
	for i in range(1, len(S1)):
		S1[i] = max(S1[i - 1], S1[i])
	MAX = max(S1)
	ACU = S[-1]
	for que in B:
		times = 0
		if que > MAX and ACU <= 0:
			print(-1, end=' ')
			continue
		elif que > MAX and ACU > 0:
			times = (que - MAX + ACU - 1) // ACU
		print(times * n + bisect.bisect_left(S1, que - times * ACU) - 1, end=' ')
	print()


import sys
input = sys.stdin.readline
from collections import *

def judge(i):
	return S * c + gain[i] >= xi

def binary_search():
	(l, r) = (0, n - 1)
	while l <= r:
		m = (l + r) // 2
		if judge(m):
			r = m - 1
		else:
			l = m + 1
	return l
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	gain = [a[0]]
	for i in range(1, n):
		gain.append(gain[-1] + a[i])
	M = max(gain)
	for i in range(1, n):
		gain[i] = max(gain[i], gain[i - 1])
	S = sum(a)
	ans = []
	for xi in x:
		if S <= 0:
			if xi > M:
				ans.append(-1)
			else:
				c = 0
				ans.append(binary_search())
		else:
			c = max(0, (xi - M + S - 1) // S)
			i = binary_search()
			ans.append(n - 1 + (c - 1) * n + i + 1)
	print(*ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()
import sys
input = sys.stdin.readline
import math
import copy
import bisect
import collections
t = int(input())
for f in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = list(map(int, input().split()))
	ans = []
	a_cum = [a[0]]
	for i in range(n - 1):
		a_cum.append(a[i + 1] + a_cum[-1])
	a_cum_max = [a_cum[0]]
	for i in range(n - 1):
		a_cum_max.append(max(a_cum_max[-1], a_cum[i + 1]))
	loop = a_cum[-1]
	for i in range(m):
		check = x[i]
		if loop <= 0 and a_cum_max[-1] < check:
			ans.append(-1)
		else:
			rep = 0
			if loop > 0 and check > a_cum_max[-1]:
				rep = (check - a_cum_max[-1] - 1) // loop + 1
			else:
				rep = 0
			temp = rep * n
			check -= rep * loop
			temp += bisect.bisect_left(a_cum_max, check)
			ans.append(temp)
	print(*ans)


t = int(input())
xs = []
pref = []
n = 0

class SegmentTree:

	def __init__(self, n):
		self.t = [0 for _ in range(n * 4)]

	def Build(self, v, tl, tr):
		if tl + 1 == tr:
			self.t[v] = pref[tl]
		else:
			tm = tl + tr >> 1
			self.Build(v * 2 + 1, tl, tm)
			self.Build(v * 2 + 2, tm, tr)
			self.t[v] = max(self.t[v * 2 + 1], self.t[v * 2 + 2])

	def Get(self, v, tl, tr, l, r, val):
		if tl >= r or tr <= l or self.t[v] < val:
			return -1
		if tl + 1 == tr:
			return tl
		else:
			tm = tl + tr >> 1
			res = self.Get(v * 2 + 1, tl, tm, l, r, val)
			if res == -1:
				return self.Get(v * 2 + 2, tm, tr, l, r, val)
			return res
tree = SegmentTree(0)

def FindPos(val):
	return tree.Get(0, 0, n, 0, n, val)
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	xs = list(map(int, input().split()))
	pref = [a[i] for i in range(n)]
	for i in range(1, n):
		pref[i] += pref[i - 1]
	tree = SegmentTree(n)
	tree.Build(0, 0, n)
	dlt = pref[-1]
	INF = 5 * 10 ** 9
	if dlt <= 0:
		for x in xs:
			pos = FindPos(x)
			print(pos, end=' ')
		print()
	else:
		mx = max(pref)
		for x in xs:
			k = max(0, (x - mx + dlt - 1) // dlt)
			ans = k * n
			x -= k * dlt
			ans += FindPos(x)
			print(ans, end=' ')
		print()


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
input = stdin.readline
prin = stdout.write
from random import sample
t = int(input())
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd

class DisjSet:

	def __init__(self, n):
		self.rank = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.rank[xset] < self.rank[yset]:
			self.parent[xset] = yset
		elif self.rank[xset] > self.rank[yset]:
			self.parent[yset] = xset
		else:
			self.parent[yset] = xset
			self.rank[xset] = self.rank[xset] + 1

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	while n % 2 == 0:
		n = n // 2
		cp += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		while n % ps == 0:
			n = n // ps
			cp += 1
	if n != 1:
		return False
	return True

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
tt = [xa ** 3 for xa in range(0, 10 ** 4 + 1)]
qq = set(tt)

def digits(k, rp):
	n = len(k)
	pq = k[::-1]
	jq = ''
	for ij in pq:
		if ij == '1':
			jq += '1'
		elif ij == '2':
			jq += '5'
		elif ij == '4' or ij == '7' or ij == '3' or (ij == '6') or (ij == '9'):
			jq += '-'
		elif ij == '5':
			jq += '2'
		elif ij == '8':
			jq += '8'
		elif ij == '0':
			jq += '0'
	if jq.find('-') != -1:
		return -1
	else:
		jl = int(jq)
		if jl >= rp:
			return -1
		else:
			return jq

def fr(a, b, h, m):
	kl = int(b)
	kl = (kl + 1) % m
	b = '0' * (2 - len(str(kl))) + str(kl)
	if b == '0' * 2:
		kj = (int(a) + 1) % h
		a = '0' * (2 - len(str(kj))) + str(kj)
	return [a, b]

def ilist():
	return [int(x) for x in input().strip().split()]

def outstrlist(array: list) -> str:
	array = [str(x) for x in array]
	return ' '.join(array)

def islist():
	return list(map(str, input().split().rstrip()))

def outfast(arr: list) -> str:
	ss = ''
	for ip in arr:
		ss += str(ip) + ' '
	return prin.write(ss)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
for jj in range(t):
	(n, m) = ilist()
	arr = ilist()
	xrr = ilist()
	sums = [0] * (n + 1)
	for i in range(1, n + 1):
		sums[i] = sums[i - 1] + arr[i - 1]
	itt = sums[n]
	lp = []
	rrr = max(sums[1:n + 1])
	xx = 0
	p = []
	dicts = {}
	cc = 0
	for i in range(1, n + 1):
		if sums[i] > xx:
			p.append(sums[i])
			dicts[cc] = i
			cc += 1
			xx = sums[i]
	for pp in range(m):
		if xrr[pp] > rrr and sums[n] <= 0:
			lp.append(-1)
			continue
		steps = 0
		if sums[n] > 0 and xrr[pp] > rrr:
			steps = ceil((xrr[pp] - rrr) / sums[n])
		ans = bl(p, xrr[pp] - sums[n] * steps, 0, len(p))
		lp.append(dicts[ans] - 1 + n * steps)
	print(outstrlist(lp))


import sys
input = sys.stdin.readline
from collections import Counter
from itertools import accumulate
import bisect
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	pre = 0
	cur = 0
	C = [(0, -1)]
	for (i, a) in enumerate(A):
		cur += a
		if cur > pre:
			C.append((cur, i))
			pre = cur
	maxv = C[-1][0]
	ans = [-1] * m
	if not maxv:
		print(*ans)
		continue
	for (i, b) in enumerate(B):
		if b <= maxv:
			idx = bisect.bisect_left(C, (b, -1))
			ans[i] = C[idx][1]
		else:
			if cur <= 0:
				continue
			rem = b - maxv
			k = (rem + cur - 1) // cur
			b -= k * cur
			idx = bisect.bisect_left(C, (b, -1))
			ans[i] = C[idx][1] + k * n
	print(*ans)


from math import ceil

def solve():
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = list(map(int, input().split()))
	s = 0
	pref = {}
	pref_s = [0]
	for j in range(n):
		s += l[j]
		if s not in pref:
			pref[s] = j
		if l[j] > 0 and s > pref_s[-1]:
			pref_s.append(s)
	for j in x:
		ans = 0
		if j <= pref_s[-1]:
			my_pref = j
		elif s <= 0:
			print(-1, end=' ')
			continue
		else:
			tmp = ceil((j - pref_s[-1]) / s)
			my_pref = max(0, j - tmp * s)
			ans += tmp * n
		ind_min = 1
		ind_max = len(pref_s) - 1
		while ind_min != ind_max:
			ind_new = (ind_min + ind_max) // 2
			if pref_s[ind_new] < my_pref:
				ind_min = ind_new + 1
			else:
				ind_max = ind_new
		print(ans + pref[pref_s[ind_max]], end=' ')
	print()
for test in range(int(input())):
	solve()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, m) = sep()
	a = lis()
	pre = [0] * (n + 1)
	curr = 0
	for i in range(n):
		curr += a[i]
		if curr > pre[i]:
			pre[i + 1] = curr
		else:
			pre[i + 1] = pre[i]
	xx = lis()
	maxi = max(pre)
	ans = []
	for i in range(m):
		x = xx[i]
		if x <= maxi:
			ind = bl(pre, x) - 1
			ans.append(ind)
		elif curr <= 0:
			ans.append(-1)
		else:
			temp = max(0, (x - maxi - 1) // curr + 1)
			ind = bl(pre, x - curr * temp) - 1
			ans.append(temp * n + ind)
	print(' '.join((str(i) for i in ans)))
testcase(int(inp()))


from __future__ import division, print_function

def main():
	from sys import stdin
	from math import ceil
	from bisect import bisect_left as bl
	input = stdin.readline
	for test in range(int(input())):
		(n, m) = map(int, input().strip().split())
		lst = list(map(int, input().strip().split()))
		x = list(map(int, input().strip().split()))
		dct = {}
		s = 0
		ans = [-1] * m
		temp = 0
		for i in range(n):
			s += lst[i]
			temp = max(temp, s)
			try:
				dct[temp]
			except KeyError:
				dct.update({s: i})
		sum_lst = list(dct.keys())
		s_max = sum_lst[-1]
		if s_max > 0:
			for i in range(m):
				if x[i] <= s_max:
					num = bl(sum_lst, x[i])
					ans[i] = dct[sum_lst[num]]
				elif s > 0:
					store = ceil((x[i] - s_max) / s)
					check = x[i] - store * s
					num = bl(sum_lst, check)
					ans[i] = dct[sum_lst[num]] + store * n
		print(*ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
for __ in range(t):
	(n, m) = map(int, input().split(' '))
	arr = [int(val) for val in input().split(' ')]
	x = [int(val) for val in input().split(' ')]
	stack = []
	csum = 0
	cmax = 0
	for a in arr:
		csum += a
		cmax = max(cmax, csum)
		stack.append(cmax)
	res = [0] * m
	for (i, y) in enumerate(x):
		if csum <= 0:
			if y > cmax:
				res[i] = -1
			else:
				left = 0
				right = len(stack)
				while left < right:
					mid = (left + right) // 2
					if stack[mid] >= y:
						right = mid
					else:
						left = mid + 1
				res[i] = left
		else:
			num_req = max(0, (y - stack[-1] + csum - 1) // csum)
			left = 0
			right = len(stack)
			while left < right:
				mid = (left + right) // 2
				if stack[mid] >= y - csum * num_req:
					right = mid
				else:
					left = mid + 1
			res[i] = num_req * n + left
	print(' '.join(map(str, res)))


__version__ = '3.0'
__date__ = '2021-03-14'
import sys
from bisect import bisect_left

def solve(n, m, a, x):
	value = 0
	accum_max = [-1]
	for i in range(n):
		value += a[i]
		accum_max.append(max(accum_max[-1], value))
	cycle_value = value
	ans = list()
	for i in range(m):
		if cycle_value <= 0 and x[i] > accum_max[-1]:
			ans.append(-1)
			continue
		if cycle_value > 0:
			k_cycle = max(x[i] - accum_max[-1], 0) // cycle_value
			if max(x[i] - accum_max[-1], 0) % cycle_value > 0:
				k_cycle += 1
		else:
			k_cycle = 0
		x[i] -= k_cycle * cycle_value
		index = bisect_left(accum_max, x[i])
		ans.append(k_cycle * n + index - 1)
	return ans

def main(argv=None):
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		x = list(map(int, input().split()))
		print(' '.join(map(str, solve(n, m, a, x))))
	return 0
STATUS = main()
sys.exit(STATUS)


import io, os, sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
in_length = int(input())
final_ouput = []

def find_minimum_stop(array, element, start, end):
	mid = (start + end) // 2
	if start == end:
		return 0
	if element == array[mid]:
		return mid
	if element <= array[mid + 1] and element > array[mid]:
		return mid + 1
	elif element > array[mid + 1]:
		return find_minimum_stop(array, element, mid + 1, end)
	elif element < array[mid]:
		return find_minimum_stop(array, element, start, mid)
for i in range(in_length):
	index_saver = dict()
	[n, m] = input().decode().split()
	acc_sum = 0
	sum_arr = input().decode().split()
	questions = input().decode().split()
	biggest_num = 0
	index_saver.update([(-1, -1)])
	check_arr = [-1]
	for j in range(int(n)):
		acc_sum += int(sum_arr[j])
		sum_arr[j] = acc_sum
		if acc_sum > biggest_num:
			index_saver.update([(sum_arr[j], j)])
			biggest_num = acc_sum
			check_arr.append(sum_arr[j])
	diff = sum_arr[-1]
	out_arr = []
	if diff <= 0:
		for q in questions:
			if int(q) > biggest_num:
				out_arr.append('-1')
			else:
				min_index = index_saver[check_arr[find_minimum_stop(check_arr, int(q), 0, len(check_arr) - 1)]]
				out_arr.append(str(min_index))
	else:
		cycle_arr = check_arr[find_minimum_stop(check_arr, biggest_num - diff, 0, len(check_arr) - 1):]
		cycle_arr.insert(0, -1)
		for q in questions:
			if int(q) <= biggest_num:
				cycles = 0
			else:
				cycles = (int(q) - biggest_num) / diff
				if cycles.is_integer():
					cycles = (int(q) - biggest_num) // diff
				else:
					cycles = (int(q) - biggest_num) // diff + 1
			if cycles == 0:
				min_index = index_saver[check_arr[find_minimum_stop(check_arr, int(q), 0, len(check_arr) - 1)]]
				out_arr.append(str(min_index))
			else:
				min_index = index_saver[cycle_arr[find_minimum_stop(cycle_arr, int(q) - diff * cycles, 0, len(cycle_arr) - 1)]]
				out_arr.append(str(min_index + int(n) * cycles))
	final_ouput.append(' '.join(out_arr))
for out in final_ouput:
	sys.stdout.write(out + '\n')


from bisect import bisect_right
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	queries = list(map(int, input().split()))
	cum = [0] * n
	cum[0] = arr[0]
	total = arr[0]
	for i in range(1, n):
		total += arr[i]
		cum[i] = max(cum[i - 1], total)
	res = [0] * m
	if total <= 0:
		for (i, x) in enumerate(queries):
			if x > cum[-1]:
				res[i] = -1
			else:
				j = bisect_right(cum, x - 1)
				res[i] = j
	else:
		for (i, x) in enumerate(queries):
			if x <= cum[-1]:
				j = bisect_right(cum, x - 1)
				res[i] = j
			else:
				a = x - cum[-1]
				q = (a + total - 1) // total
				r = x - q * total
				j = bisect_right(cum, r - 1)
				res[i] = n * q + j
	print(*res)


from math import ceil
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	mpfa = [0] * n
	mpfi = 0
	pf = mpfa[0] = a[0]
	for i in range(1, n):
		pf += a[i]
		if pf > mpfa[i - 1]:
			mpfi = i
			mpfa[i] = pf
		else:
			mpfa[i] = mpfa[i - 1]
	ans = []
	xli = map(int, input().split())
	for x in xli:
		if x <= mpfa[-1]:
			low = 0
			high = n - 1
			while low < high:
				mid = (low + high) // 2
				if mpfa[mid] >= x:
					high = mid
				else:
					low = mid + 1
			ans.append(high)
			continue
		elif s <= 0:
			ans.append(-1)
		else:
			iters = ceil((x - mpfa[-1]) / s)
			low = 0
			high = n - 1
			while low < high:
				mid = (low + high) // 2
				if mpfa[mid] >= x - s * iters:
					high = mid
				else:
					low = mid + 1
			ans.append(iters * n + high)
	print(*ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	xs = list(map(int, input().split()))
	pref = [a[i] for i in range(n)]
	pref_max = [a[i] for i in range(n)]
	for i in range(1, n):
		pref[i] += pref[i - 1]
		pref_max[i] = max(pref[i], pref_max[i - 1])
	dlt = pref[-1]
	ans = []
	if dlt <= 0:
		for x in xs:
			l = 0
			r = n - 1
			m = 0
			res = n
			while l <= r:
				m = l + r >> 1
				if pref_max[m] >= x:
					res = m
					r = m - 1
				else:
					l = m + 1
			if res == n:
				res = -1
			ans.append(str(res))
	else:
		mx = max(pref)
		for x in xs:
			k = max(0, (x - mx + dlt - 1) // dlt)
			x -= k * dlt
			l = 0
			r = n - 1
			m = 0
			res = n
			while l <= r:
				m = l + r >> 1
				if pref_max[m] >= x:
					res = m
					r = m - 1
				else:
					l = m + 1
			ans.append(str(k * n + res))
	print(' '.join(ans))


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = get_ints()
	a = get_array()
	x = get_array()
	b = [[a[0], 0]]
	cur = a[0]
	mx = a[0]
	for i in range(1, n):
		if cur + a[i] > b[-1][0]:
			b.append([cur + a[i], i])
		cur += a[i]
		mx = max(mx, cur)
	length = len(b)
	res = []
	for ele in x:
		if ele <= mx:
			l = 0
			r = length - 1
			while l <= r:
				m = (l + r) // 2
				if b[m][0] >= ele:
					r = m - 1
				else:
					l = m + 1
			res.append(b[l][1])
		elif cur > 0:
			y = (ele - mx) // cur
			ele -= y * cur
			if ele > mx:
				y += 1
				ele -= cur
			l = 0
			r = length - 1
			while l <= r:
				m = (l + r) // 2
				if b[m][0] >= ele:
					r = m - 1
				else:
					l = m + 1
			res.append(b[l][1] + y * n)
		else:
			res.append(-1)
	print(*res)