
import math
t=int(input())
for j in range(t):
	k=int(input())
	l=list(map(int,input().split()))
	n,p,c=[],[],0
	for i in range(len(l)):
		if l[i]>0:
			p.append(l[i])
			if i>0 and l[i-1]<0:
				c=c+max(n)
				n=[]
			if i==k-1:
				c=c+max(p)
		else:
			n.append(l[i])
			if i>0 and l[i-1]>0:
				c=c+max(p)
				p=[]
			if i==k-1:
				c=c+max(n)
	print(c)
			
		



   


        
