for _ in range(int(input())):
	a = int(input())
	lis = list(map(int,input().split()))
	def checksi(i):
		if i > 0 :
			return ("+")
		else:
			return "-"
	i = 0
	ak = lis[0]
	summ = 0
	fag = False
	while i < a-1:
		if checksi(lis[i+1])==checksi(lis[i]):
			if checksi(lis[i])=="+":
				ak = max(ak,lis[i],lis[i+1])
			elif checksi(lis[i])=="-":
				ak = max(ak,lis[i],lis[i+1])
			if i==a-2:
				summ+=ak
		else:
			if i==a-2 and fag:
				summ += lis[-1]
				summ+= ak
			else:
				fag = True
				summ+= ak
				if i < a-1:
					ak = lis[i+1]
		i+=1
	if fag:
		print(summ)
	else:
		print(-1)

