# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w') 


for _ in range(int(input())):
	n=int(input())
	li=[int(x) for x in input().split()]

	neg=0
	pos=0
	ans=0

	k=0
	size=0
	for i in li:
		if(n==1):
			ans=li[0]
		else:
			if(i<0 and k==0):
				ans = ans+i
				size+=1
				k=1
				neg=i
			elif(i<0 and k==1 and size==2):
				ans =  max(ans, i+pos)
				neg=max(neg, i)
			elif(i<0 and k==1 and size!=2):
				neg=max(neg,i)


			elif(i>0 and k==1):
				ans = ans+i
				size+=1
				k=0
				pos=i
			elif(i>0 and k==0 and size==2):
				ans =  max(ans, i+pos)
				pos=max(pos, i)
			elif(i>0 and k==1 and size!=2):
				pos=max(pos,i)
	print(ans)