For an array of non-negative integers $a$ of size $n$, we construct another array $d$ as follows: $d_1 = a_1$, $d_i = |a_i - a_{i - 1}|$ for $2 \le i \le n$.

Your task is to restore the array $a$ from a given array $d$, or to report that there are multiple possible arrays.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.

The first line of each test case contains one integer $n$ ($1 \le n \le 100$) — the size of the arrays $a$ and $d$.

The second line contains $n$ integers $d_1, d_2, \dots, d_n$ ($0 \le d_i \le 100$) — the elements of the array $d$.

It can be shown that there always exists at least one suitable array $a$ under these constraints.


-----Output-----

For each test case, print the elements of the array $a$, if there is only one possible array $a$. Otherwise, print $-1$.


-----Examples-----

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


-----Note-----

In the second example, there are two suitable arrays: $[2, 8, 5]$ and $[2, 8, 11]$.

Difficulty: EASY
Tags: Greedy algorithms

Mathematics

Constructive algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	ds = input().split()
	ds = [int(d) for d in ds]
	is_weiyi = True
	arr = [ds[0]]
	for d in ds[1:]:
		if d > 0 and d <= arr[-1]:
			is_weiyi = False
			break
		arr.append(arr[-1] + d)
	if is_weiyi:
		print(' '.join([str(i) for i in arr]))
	else:
		print(-1)


def test():
	input()
	b = list(map(int, input().split()))
	a = [b[0]]
	for x in b[1:]:
		if x <= a[-1] and x != 0:
			print(-1)
			return
		else:
			a += [a[-1] + x]
	print(' '.join(map(str, a)))
t = int(input())
for _ in range(t):
	test()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = [arr[0]]
	valid = True
	for i in range(1, n):
		if d[-1] >= arr[i] and arr[i] > 0:
			valid = False
			break
		d.append(d[-1] + arr[i])
	if valid:
		print(*d)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	ans = [d[0]]
	f = 1
	for i in range(1, n):
		if ans[i - 1] - d[i] >= 0:
			if d[i] != 0:
				f = 0
				break
			else:
				ans.append(ans[i - 1] + d[i])
		else:
			ans.append(ans[i - 1] + d[i])
	if f:
		print(*ans)
	else:
		print(-1)


from math import *
for z in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	ans = [str(d[0])]
	for i in range(1, n):
		if d[i] != 0:
			if d[i] <= int(ans[-1]):
				print(-1)
				break
		ans.append(str(int(ans[-1]) + d[i]))
	else:
		print(' '.join(ans))


t = int(input())
for ttt in range(t):
	n = int(input())
	d = [int(i) for i in input().split()]
	ans = [str(d[0])]
	for i in range(1, n):
		l = int(ans[-1])
		if l < d[i] or d[i] == 0:
			ans.append(str(l + d[i]))
		else:
			print(-1)
			break
	else:
		print(' '.join(ans))


t = int(input())

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	res = []
	for i in a:
		if s >= i and i:
			print(-1)
			return
		s += i
		res.append(s)
	print(' '.join(map(str, res)))
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	num = [lis[0]]
	flag = False
	for i in range(1, n):
		if lis[i] == 0:
			num.append(num[-1])
		elif num[-1] - lis[i] >= 0:
			flag = True
			break
		else:
			num.append(num[-1] + lis[i])
	if flag:
		print(-1)
	else:
		print(*num)


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	a.append(d[0])
	for i in range(1, n):
		x = d[i]
		y = -1 * x + a[-1]
		z = 1 * x + a[-1]
		if y >= 0 and z >= 0 and (y != z):
			break
		a.append(max(y, z))
	if len(a) == n:
		print(*a)
	else:
		print(-1)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	curr = arr[0]
	final = [curr]
	for i in range(1, n):
		if arr[i] == 0:
			final.append(curr)
			continue
		if curr - arr[i] >= 0:
			print(-1)
			return
		curr += arr[i]
		final.append(curr)
	for z in final:
		print(z, end=' ')
	print()
	return
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	sol = [arr[0]]
	there = False
	for i in range(1, len(arr)):
		if min(sol[-1] - arr[i], arr[i] + sol[-1]) < 0 or not arr[i]:
			sol.append(max(sol[-1] - arr[i], arr[i] + sol[-1]))
		else:
			there = True
			break
	if there:
		print(-1)
	else:
		for x in sol:
			print(x, end=' ')
		print()


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

def inp_int():
	return int(input())

def inp_str():
	return input()

def solve():
	(n,) = inp_arr()
	a = inp_arr()
	for i in range(1, n):
		if a[i] != 0 and a[i] <= a[i - 1]:
			print(-1)
			return
		a[i] = a[i] + a[i - 1]
	for x in a:
		print(x, end=' ')
	print()
tt = inp_int()
for t in range(tt):
	solve()


for _ in range(int(input())):
	a = int(input())
	b = [int(I) for I in input().split()]
	c = [b[0]]
	check = 1
	for i in range(1, a):
		d = b[i]
		if d and c[-1] + d >= 0 and (c[-1] - d >= 0):
			check = 0
			break
		else:
			c.append(max(c[-1] + d, c[-1] - d))
	if check:
		for i in c:
			print(i, end=' ')
		print()
	else:
		print(-1)


import sys
readline = sys.stdin.readline
T = int(readline())
for _ in range(T):
	N = int(readline())
	S = list(map(int, readline().split()))
	A = [S[0]]
	for i in range(1, N):
		s = S[i]
		a = A[i - 1]
		tmp = sorted({s + a, -s + a})
		if len(tmp) == 1 or tmp[0] < 0:
			A.append(tmp[-1])
		else:
			print(-1)
			break
	else:
		print(*A)


from sys import stdin, stdout

def solve():
	n = int(stdin.readline())
	d = list(map(int, stdin.readline().split()))
	a = [d[0]] * n
	for i in range(1, n):
		if d[i] == 0:
			a[i] = a[i - 1]
		elif d[i] > a[i - 1]:
			a[i] = d[i] + a[i - 1]
		else:
			print(-1)
			return
	res = ''
	for i in range(n):
		res += str(a[i]) + ' '
	print(res)

def main():
	t = int(stdin.readline())
	for i in range(t):
		solve()
main()


import sys
sys.setrecursionlimit(1000000)

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

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())

def check(n, m, x, y):
	return x - 2 >= 1 and y - 1 >= 1 or (y - 2 >= 1 and x - 1 >= 1) or (x - 2 >= 1 and y + 1 <= m) or (y - 2 >= 1 and x + 1 <= n) or (x + 2 <= n and y - 1 >= 1) or (y + 2 <= m and x - 1 >= 1) or (x + 2 <= n and y + 1 <= m) or (y + 2 <= m and x + 1 <= n)
for T in range(int(input())):
	n = ni()
	d = li()
	flag = True
	ans = [d[0]]
	for i in range(1, n):
		if ans[-1] + d[i] >= 0 and ans[-1] - d[i] >= 0 and (ans[-1] + d[i] != ans[-1] - d[i]):
			print(-1)
			flag = False
			break
		ans.append(d[i] + ans[-1])
	if flag:
		print(*ans)


for i in range(int(input())):
	n = int(input())
	values = list(map(int, input().split()))
	out = []
	j = 1
	flag = 0
	su = values[0]
	out.append(values[0])
	while j < n:
		if values[j] == 0:
			su += values[j]
			out.append(su)
		elif su < values[j]:
			su += values[j]
			out.append(su)
		else:
			flag = 1
			break
		j += 1
	if flag == 1:
		print(-1)
	else:
		for val in out:
			print(val, end=' ')
		print()


t = int(input())
for _ in range(t):
	n = int(input())
	D = list(map(int, input().split()))
	A = []
	A.append(D[0])
	for i in range(1, n):
		if D[i] != 0 and A[i - 1] - D[i] >= 0:
			A = -1
			break
		else:
			A.append(A[i - 1] + D[i])
	if A == -1:
		print(A)
	else:
		for i in range(n):
			if i == n - 1:
				print(A[i])
			else:
				print(A[i], end=' ')


t = int(input())
for i in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	ans = []
	s = d[0]
	ans.append(s)
	c = 0
	for i in range(1, n):
		x = s + d[i]
		y = s - d[i]
		if x >= 0 and y >= 0 and (x != y):
			c = -1
			break
		else:
			s = max(x, y)
			ans.append(s)
	if c == -1:
		print(-1)
	else:
		print(*ans)


def loop(s, d, n):
	ans = [s]
	for i in range(1, n):
		if d[i] and s - d[i] >= 0:
			return [-1]
		s += d[i]
		ans.append(s)
	return ans
for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	s = d[0]
	ans = loop(s, d, n)
	print(*ans, sep=' ')


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = [d[0]]
	result = 0
	for i in range(1, n):
		(x, y) = (a[i - 1] + d[i], a[i - 1] - d[i])
		if x * y < 0 or x == y:
			a.append(max(x, y))
		else:
			result = -1
			break
	if result == -1:
		print(-1)
	else:
		print(*a)


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	if d.count(0) == n:
		print(*d)
	else:
		for i in range(0, n):
			if i == 0:
				a.append(d[i])
			elif a[i - 1] < d[i]:
				a.append(a[i - 1] + d[i])
			elif d[i] == 0:
				a.append(a[i - 1])
			elif a[i - 1] >= d[i]:
				print(-1)
				break
		if len(a) == n:
			print(*a)


testcases = int(input())
for i in range(testcases):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	a.append(d[0])
	for j in range(1, n):
		if d[j] == 0 or a[j - 1] < d[j]:
			a.append(d[j] + a[j - 1])
		else:
			break
	if len(a) == len(d):
		print(*a)
	else:
		print(-1)


for Pythonic__Python in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [l[0]]
	for i in range(n - 1):
		if ans[i] - l[i + 1] >= 0 and l[i + 1] != 0:
			ans = [-1]
			break
		else:
			ans.append(ans[i] + l[i + 1])
	print(*ans)


import sys
t = int(sys.stdin.readline())

def solve():
	n = int(sys.stdin.readline())
	d = list(map(int, sys.stdin.readline().split()))
	a = [d[0]]
	for i in d[1:]:
		x = a[-1] + i
		y = a[-1] - i
		if x < 0 and y < 0:
			break
		elif x >= 0 and x == y:
			a.append(x)
		elif x >= 0 and y >= 0:
			break
		else:
			a.append(x if x >= 0 else y)
	if len(a) == n:
		print(*a)
	else:
		print(-1)
for _ in range(t):
	solve()


T = int(input())
for _ in range(T):
	_ = input()
	arr = list(map(int, input().split()))
	val = arr[0]
	ans = [val]
	for n in arr[1:]:
		if n != 0 and val - n >= 0:
			print(-1)
			break
		val += n
		ans.append(val)
	else:
		print(*ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	prev = 0
	d = [0] * n
	d[0] = l[0]
	prev = l[0]
	c = 0
	for j in range(1, n):
		if -l[j] + prev != l[j] + prev and -l[j] + prev >= 0:
			print(-1)
			c = 1
			break
		else:
			prev += l[j]
			d[j] = prev
	if c == 0:
		for j in d:
			print(j, end=' ')
		print()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = 0
	for i in range(1, n):
		a = l[i - 1] + l[i]
		b = l[i - 1] - l[i]
		if a >= 0 and b >= 0 and (a != b):
			k = 1
			break
		else:
			l[i] = a
	if k == 1:
		print(-1)
	else:
		for i in range(n):
			print(l[i], end=' ')
		print()


def recover(d):
	a = []
	for i in range(len(d)):
		if i == 0:
			a.append(d[i])
		else:
			a1 = d[i] + a[i - 1]
			a2 = -d[i] + a[i - 1]
			if a1 >= 0 and a2 >= 0 and (not a1 == a2):
				return -1
			elif a1 >= 0:
				a.append(a1)
			elif a2 >= 0:
				a.append(a2)
			else:
				return -1
	return a
l = []
n = int(input())
o = []
for _ in range(n):
	a = int(input())
	l.append(list(map(int, input().split())))
for d in l:
	o.append(recover(d))
for i in o:
	if i == -1:
		print(-1)
		continue
	print(' '.join(map(str, i)))


t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		if m[i + 1] <= m[i] and m[i + 1] != 0:
			ans -= 1
			break
		else:
			m[i + 1] = abs(m[i + 1] + m[i])
	if ans == -1:
		print(ans)
	else:
		print(*m)


test = int(input())
while test:
	test -= 1
	N = int(input())
	d = list(map(int, input().split()))
	a = [0] * N
	a[0] = d[0]
	flag = 0
	for i in range(1, N):
		x1 = a[i - 1] + d[i]
		x2 = a[i - 1] - d[i]
		if x1 != x2 and x1 >= 0 and (x2 >= 0):
			flag = 1
			break
		else:
			a[i] = max(x1, x2)
	if flag:
		print('-1')
	else:
		for i in a:
			print(i, end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [a[0]]
	for i in range(1, len(a)):
		if a[i] + ans[-1] >= 0 and (a[i] <= ans[-1] and a[i] != 0):
			ans = -1
			break
		else:
			ans.append(a[i] + ans[-1])
	if ans == -1:
		print(ans)
	else:
		print(' '.join([str(i) for i in ans]))


t = int(input())
for i in range(t):
	a = int(input())
	b = list(map(int, input().split()))
	c = []
	c.append(str(b[0]))
	for i in range(len(b) - 1):
		if b[i + 1] != 0 and int(c[len(c) - 1]) - b[i + 1] >= 0:
			print('-1')
			break
		else:
			c.append(str(int(c[len(c) - 1]) + b[i + 1]))
	if len(c) == a:
		print(' '.join(c))


t = int(input())
for i in range(t):
	n = int(input())
	d = [int(_) for _ in input().split(' ')]
	arr = [d[0]]
	isError = False
	for i in range(1, n):
		if d[i] != 0 and d[i] + arr[-1] >= 0 and (arr[-1] - d[i] >= 0):
			isError = True
			break
		arr.append(d[i] + arr[-1])
	if isError:
		print(-1)
	else:
		print(*arr)


t = int(input())
for i in range(t):
	size = int(input())
	d = list(map(int, input().split()))
	s = [d[0]]
	c = 1
	for i in range(0, size - 1):
		x1 = s[i] + d[i + 1]
		x2 = s[i] - d[i + 1]
		if x1 >= 0 and x2 >= 0:
			if x1 == x2:
				s.append(x1)
			else:
				print(-1)
				c -= 1
				break
		elif x1 >= 0:
			s.append(x1)
		elif x2 >= 0:
			s.append(x2)
	if c == 1:
		print(*s)


for i in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	ans = 0
	val = [0] * 1000
	for i in range(n):
		val[i + 1] = d[i]
	for k in range(1, n):
		if val[k + 1] <= val[k] and val[k + 1] != 0:
			ans = -1
			break
		else:
			val[k + 1] = abs(val[k] + val[k + 1])
	if ans == -1:
		print(ans)
	else:
		print(*val[1:n + 1])


tests = int(input().strip())
multiple = False
for _ in range(tests):
	n = int(input().strip())
	d = list(map(int, input().strip().split()))
	a = [d[0]]
	for i in range(1, n):
		aplus = d[i] + a[i - 1]
		aminus = -d[i] + a[i - 1]
		if aplus < 0:
			a.append(aminus)
		elif aminus < 0:
			a.append(aplus)
		elif aplus == aminus:
			a.append(aplus)
		else:
			multiple = True
			break
	out = ''
	if multiple:
		out = '-1'
		multiple = False
	else:
		for i in range(n):
			out += str(a[i])
			out += ' '
	print(out)


q = int(input())
while bool(q):
	n = input()
	inp = input()
	ls = inp.split(sep=' ')
	dif = ls[0]
	ls2 = [dif]
	bl = False
	for i in range(1, len(ls)):
		if int(dif) - int(ls[i]) < 0 or ls[i] == '0':
			dif = int(dif) + int(ls[i])
			ls2.append(dif)
		else:
			bl = True
	if bl:
		print(-1)
	else:
		for it in ls2:
			print(it, end=' ')
		print()
	q -= 1


for s in [*open(0)][2::2]:
	r = []
	t = f = 0
	for x in map(int, s.split()):
		f |= 0 < x <= t
		t += x
		r += (t,)
	print(*(r, [-1])[f])


for t in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split(' ')))
	ans = [lst[0]]
	flag = True
	for i in lst[1:]:
		x = ans[-1] + i
		y = ans[-1] - i
		if x * y >= 0 and x != y:
			print(-1)
			flag = False
			break
		ans.append(ans[-1] + i)
	if flag:
		for i in ans:
			print(i, end=' ')
		print()


tescase = int(input())
arrays = []
sizes = []
for i in range(tescase):
	sizes.append(int(input()))
	inp = input().split()
	ar = [int(i) for i in inp]
	arrays.append(ar)

def restore(array):
	newarr = [array[0]]
	for i in array[1:]:
		el1 = newarr[-1] + i
		el2 = newarr[-1] - i
		if el1 >= 0 and el2 >= 0 and (el1 != el2):
			return -1
		if el2 >= 0:
			newarr.append(el2)
		else:
			newarr.append(el1)
	return newarr
for array in arrays:
	res = restore(array)
	if res == -1:
		print(res)
	else:
		print(*res)


t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = [l[0]]
	f = 0
	for i in range(1, len(l)):
		x = l[i] + a[i - 1]
		y = -l[i] + a[i - 1]
		if x * y >= 0 and x != y:
			f = -1
			break
		else:
			a.append(max(x, y))
	if f == -1:
		print(-1)
	else:
		print(''.join([str(p) + ' ' for p in a]))


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	ans = [num[0]]
	f = 1
	for i in range(1, n):
		x = ans[i - 1] + num[i]
		y = ans[i - 1] - num[i]
		if y < 0:
			y = x
		if y >= 0 and y != x:
			f = 0
			break
		ans.append(x)
	if f == 0:
		print(-1)
	else:
		print(*ans)


for _ in range(int(input().strip())):
	n = int(input())
	l = list(map(int, input().split()))
	l2 = [l[0]]
	c = 1
	for i in range(1, n):
		if l2[i - 1] + l[i] >= 0 and l2[i - 1] - l[i] >= 0 and (l[i] != 0):
			c = 0
			break
		l2.append(l2[i - 1] + l[i])
	if c:
		print(*l2)
	else:
		print(-1)


def int_input():
	a = int(input())
	return a

def int_list_input():
	a = list(map(int, input().split()))
	return a

def solve():
	n = int_input()
	d = int_list_input()
	ans = [i for i in d]
	for i in range(1, n):
		y = ans[i - 1] - d[i]
		x = ans[i - 1] + d[i]
		if x >= 0 and y >= 0 and (x != y):
			print(-1)
			return
		ans[i] = max(ans[i - 1] + d[i], ans[i - 1] - d[i])
	print(*ans)
for _ in range(int(input())):
	solve()


for __ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = [0] * n
	a[0] = d[0]
	ans = True
	for i in range(1, n):
		if a[i - 1] - d[i] >= 0 and a[i - 1] - d[i] != d[i] + a[i - 1]:
			ans = False
		else:
			a[i] = d[i] + a[i - 1]
	if ans:
		print(*a)
	else:
		print(-1)


t = int(input())
while t > 0:
	n = int(input())
	d = list(map(int, input().split()))
	ans = []
	ans.append(d[0])
	l = 0
	k = 0
	for i in range(1, n):
		if ans[l] >= d[i] and ans[l] - d[i] != ans[l] + d[i]:
			print(-1)
			k = 1
			break
		ans.append(ans[l] + d[i])
		l += 1
	if k == 0:
		for i in range(n):
			print(ans[i], end=' ')
		print(end='\n')
	t -= 1


t = int(input())
for _ in range(0, t):
	n = int(input())
	list1 = [int(num) for num in input().split()]
	list2 = []
	list2.append(list1[0])
	c = 0
	for i in range(1, n):
		if list1[i] == 0:
			list2.append(list2[i - 1])
		elif list2[i - 1] < list1[i]:
			list2.append(list1[i] + list2[i - 1])
		else:
			c = 1
			break
	if c == 1:
		print(-1)
	else:
		print(*list2)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [a[0]]
	flag = True
	for i in range(1, n):
		if a[i] <= b[i - 1] and a[i] != 0:
			flag = False
			break
		else:
			b.append(b[i - 1] + a[i])
	if flag == False:
		print(-1)
	else:
		print(*b)


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	f = 1
	a = [d[0]]
	for i in range(n - 1):
		if d[i + 1] > 0 and d[i + 1] <= a[-1]:
			f = 0
			break
		a.append(a[-1] + d[i + 1])
	if not f:
		print(-1)
	else:
		print(*a)


def solve():
	for t in range(int(input())):
		n = int(input())
		diff = [int(x) for x in input().split()]
		arr = []
		arr.append(diff[0])
		flag = False
		for i in range(1, len(diff)):
			x = arr[i - 1] + diff[i]
			y = arr[i - 1] - diff[i]
			if y >= 0 and x != y:
				flag = True
				break
			else:
				arr.append(x)
		if flag:
			print(-1)
		else:
			for i in arr:
				print(i, end=' ')
			print()
solve()


def check(a):
	sum = 0
	for i in a:
		if i <= sum and i != 0:
			return False
		sum += i
	return True
n = int(input())
for i in range(n):
	m = int(input())
	a = list(map(int, input().split()))
	if check(a):
		sum = 0
		for i in a:
			sum += i
			print(sum, end=' ')
	else:
		print(-1, end='')
	print()


from collections import Counter

def lstRd() -> list:
	return list(map(int, input().split()))

def intRd():
	return int(input())

def lstStrRd():
	return list(input())
for _ in range(intRd()):
	n = intRd()
	a = lstRd()
	res = [a[0]]
	temp = a[0]
	worked = True
	for i in range(1, len(a)):
		if temp - a[i] < 0 or a[i] == 0:
			temp += a[i]
		else:
			print(-1)
			res = []
			worked = False
			break
		res.append(temp)
	if worked:
		for i in res:
			print(i, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	i = l[0]
	h = False
	l1 = [l[0]]
	for j in l[1:]:
		if j <= i and j != 0:
			h = True
			break
		else:
			l1.append(j + i)
			i += j
	if h:
		print(-1)
	else:
		print(*l1)


for _ in range(int(input())):
	n = int(input())
	ans = [0]
	for x in map(int, input().split()):
		if x != 0 and ans[-1] - x >= 0:
			print(-1)
			break
		else:
			ans.append(ans[-1] + x)
	else:
		print(*ans[1:])


t = eval(input())
for i in range(t):
	n = eval(input())
	d = list(map(int, input().split()))
	p = 0
	c = []
	a1 = d[0]
	c.append(a1)
	for i in range(1, n):
		if (a1 - d[i]) * (a1 + d[i]) >= 0 and d[i] != 0:
			print(-1)
			p = 1
			break
		else:
			c.append(max(a1 - d[i], a1 + d[i]))
			a1 = c[-1]
	if p == 0:
		print(*c)


for i in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = [d[0]]
	for j in range(1, n):
		if d[j] + a[j - 1] < 0 or (a[j - 1] - d[j] >= 0 and a[j - 1] - d[j] != d[j] + a[j - 1]):
			print(-1)
			break
		a.append(d[j] + a[j - 1])
	else:
		print(*a, sep=' ')


tc = int(input())
for i in range(tc):
	n = int(input())
	d = [int(x) for x in input().split()]
	a = [d[0]]
	for v in d[1:]:
		if v != 0 and a[-1] >= v:
			print(-1)
			break
		else:
			a.append(v + a[-1])
	else:
		print(*a)


t = int(input())
for ind in range(t):
	n = int(input())
	d = list(map(int, input().strip().split()))[:n]
	a = [d[0]]
	boolean = True
	for i in range(1, n):
		if a[i - 1] - d[i] >= 0 and d[i] != 0:
			boolean = False
			break
		else:
			a.append(d[i] + a[i - 1])
	if boolean:
		print(*a)
	else:
		print(-1)


for i in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	for j in range(n):
		if j == 0:
			a.append(d[j])
		elif a[j - 1] >= d[j] and d[j] != 0:
			print(-1)
			break
		else:
			a.append(a[j - 1] + d[j])
	if len(a) == n:
		print(*a)


t = int(input())
for i in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	c = 0
	for j in range(n):
		if j == 0:
			a.append(d[j])
		elif d[j] > a[j - 1] or d[j] == 0:
			a.append(a[j - 1] + d[j])
		else:
			c = 1
			break
	if c == 1:
		print(-1)
	else:
		for j in range(n):
			print(a[j], end=' ')
		print()


tq = int(input())
for i in range(tq):
	n = int(input())
	d = list(map(int, input().split()))
	a = [0] * n
	a[0] = d[0]
	count = 0
	for j in range(1, n):
		q = d[j] + a[j - 1]
		qr = -d[j] + a[j - 1]
		if q >= 0 and qr >= 0 and (q != qr):
			count = 1
			break
		if q >= 0 and qr < 0:
			a[j] = q
		if q < 0 and qr >= 0:
			a[j] = qr
		if q > 0 and qr > 0 and (q == qr):
			a[j] = q
	a1 = []
	for j in a:
		a1.append(str(j))
	if count == 1:
		print('-1')
	else:
		print(' '.join(a1))


t = int(input())
while t > 0:
	n = int(input())
	d = [int(x) for x in input().split()]
	a = [d[0]]
	flag = True
	for i in range(1, n):
		x1 = a[i - 1] + d[i]
		x2 = a[i - 1] - d[i]
		if x1 != x2 and x2 >= 0:
			flag = False
			break
		a.append(x1)
	if flag:
		for i in range(n):
			print(a[i], end=' ')
		print()
	else:
		print(-1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	d = list(map(int, input().split()))
	flag = True
	for i in range(1, n):
		if d[i - 1] >= d[i] and d[i] != 0:
			flag = False
			print(-1)
			break
		d[i] = d[i] + d[i - 1]
	if flag:
		print(*d)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = list()
	ans.append(arr[0])
	for i in range(1, n):
		if ans[i - 1] - arr[i] < 0 or arr[i] == 0:
			ans.append(ans[i - 1] + arr[i])
		else:
			ans.clear()
			ans.append(-1)
			break
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	elem = 0
	exist = True
	for i in range(n - 1):
		elem += d[i]
		if d[i + 1] == 0:
			a.append(elem)
		elif elem < d[i + 1]:
			a.append(elem)
		else:
			print(-1)
			exist = False
			break
	if exist:
		a.append(elem + d[-1])
		print(' '.join([str(s) for s in a]))


for _ in range(int(input())):
	len1 = int(input())
	d = list(map(int, input().rstrip().split()))
	a = [d[0]]
	flag = False
	for i in range(1, len1):
		t1 = a[i - 1] + d[i]
		t2 = a[i - 1] - d[i]
		if t1 < 0:
			a.append(t2)
		elif t2 < 0:
			a.append(t1)
		elif t1 == t2:
			a.append(t1)
		else:
			flag = True
			break
	if flag:
		print(-1)
	else:
		print(*a)


for _ in range(int(input())):
	n = int(input())
	d = [int(i) for i in input().split()]
	a = [d[0]]
	t = True
	for i in range(1, n):
		x = a[i - 1] + d[i]
		y = a[i - 1] - d[i]
		if x < 0 and y < 0 or (x >= 0 and y >= 0 and (x != y)):
			print(-1)
			t = False
			break
		elif x < 0:
			a.append(y)
		else:
			a.append(x)
	if t:
		print(*a)


t = int(input())
for x in range(t):
	n = int(input())
	d = list(map(int, input().split()))
	a = []
	a.append(d[0])
	for i in range(1, len(d)):
		a.append(d[i] + a[i - 1])
	count = 0
	for i in range(1, len(d)):
		if d[i] <= a[i - 1] and d[i] != 0:
			count += 1
	if count > 0:
		print(-1)
	else:
		print(*a)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	b[0] = a[0]
	for r in range(1, n):
		if b[r - 1] - a[r] < 0 or a[r] == 0:
			b[r] = b[r - 1] + a[r]
		else:
			print(-1)
			break
	else:
		print(' '.join(map(str, b)))


test = int(input())
for t in range(test):
	n = int(input())
	d = list(map(int, input().split()))
	a = [d[0]]
	nope = False
	for i in range(1, n):
		if a[i - 1] - d[i] >= 0 and d[i] != 0:
			nope = True
		else:
			a.append(a[i - 1] + d[i])
		if nope:
			break
	if nope:
		print(-1)
	else:
		print(*a)


def solve():
	n = int(input())
	d = list(map(int, input().split()))
	a = [0] * n
	a[0] = d[0]
	flag = 0
	for i in range(1, n):
		a[i] = a[i - 1] + d[i]
		if a[i - 1] >= d[i] and d[i] != 0:
			flag = 1
			break
	if flag:
		print(-1)
	else:
		print(' '.join((str(x) for x in a)))
for t in range(0, int(input())):
	solve()


result = []
for _ in range(int(input())):
	input()
	D = map(int, input().split())
	A = [next(D)]
	for (d, i) in enumerate(D, start=1):
		if A[d - 1] >= i and i != 0:
			result.append(None)
			break
		A.append(i + A[d - 1])
	else:
		result.append(A)
for line in result:
	if not line:
		print(-1)
	else:
		print(' '.join(map(str, line)))


def solve():
	_ = input()
	ans = [0]
	for x in map(int, input().split()):
		if x != 0 and ans[-1] - x >= 0:
			print(-1)
			return
		ans.append(ans[-1] + x)
	print(*ans[1:])
tc = 1
tc = int(input())
while tc > 0:
	solve()
	tc -= 1


t = int(input())
while t != 0:
	n = int(input())
	d = list(map(int, input().split()))
	a = list()
	b = list()
	a.append(d[0])
	b.append(d[0])
	for i in range(1, n):
		z = a[i - 1] + d[i]
		a.append(z)
	for i in range(1, n):
		y = b[i - 1] - d[i]
		if y >= 0:
			b.append(y)
		elif y < 0:
			s = b[i - 1] + d[i]
			b.append(s)
	m = ' '
	if a == b:
		print(m.join(map(str, a)))
	else:
		print(-1)
	t -= 1


import sys

def solve(d):
	tot = d[0]
	a = [tot]
	for i in range(1, len(d)):
		if d[i] <= tot and d[i] != 0:
			return -1
		tot += d[i]
		a.append(tot)
	return ' '.join([str(i) for i in a])
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	d = [int(d_i) for d_i in sys.stdin.readline().strip().split()]
	print(solve(d))


for _ in range(int(input())):
	sol = int(input())
	ans = [0]
	for vr in map(int, input().split()):
		if vr != 0 and ans[-1] - vr >= 0:
			print(-1)
			break
		else:
			ans.append(ans[-1] + vr)
	else:
		print(*ans[1:])


for s in [*open(0)][2::2]:
	a = []
	c = h = 0
	for x in map(int, s.split()):
		h |= 0 < x <= c
		c += x
		a += (c,)
	print(*(a, [-1])[h])


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(k) for k in input().split()]
	curr = []
	curr.append(a[0])
	v = True
	for j in range(1, n):
		if a[j] <= curr[j - 1] and a[j] > 0:
			print(-1)
			v = False
			break
		curr.append(curr[j - 1] + a[j])
	if v:
		print(*curr)


for asdasdas in range(int(input())):
	n = int(input())
	items_d = [int(i) for i in input().split()]
	items_a = [items_d[0]] + [0] * (n - 1)
	for i in range(1, n):
		gg = items_d[i] + items_a[i - 1]
		gg2 = -(items_d[i] - items_a[i - 1])
		if 0 <= gg != gg2 >= 0:
			print(-1)
			break
		res = max(gg, gg2)
		items_a[i] = res
	else:
		print(*items_a)


t = int(input())
for i in range(t):
	n = int(input())
	d = [int(j) for j in input().split()]
	a = []
	a.append(d[0])
	for j in range(1, n):
		if d[j] <= a[j - 1] and d[j] != 0:
			print(-1)
			break
		else:
			a.append(d[j] + a[j - 1])
	if len(a) == n:
		print(*a)