from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	z=[]
	if l[0]>0:
		flag=1
	else:
		flag=0
	m1=float("-infinity")
	m2=float("-infinity")
	for i in range(n):
		if flag==0:
			if l[i]>0:
				z.append(m1)
				m1=float("-infinity")
				m2=max(m2,l[i])
				flag=1
			else:
				m1=max(m1,l[i])
		else:
			if l[i]<0:
				z.append(m2)
				m2=float("-infinity")
				m1=max(m1,l[i])
				flag=0
			else:
				m2=max(m2,l[i])
		# print(z)
	if m1==float("-infinity"):
		z.append(m2)
	else:
		z.append(m1)
	print(sum(z))
