import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def case():
	n=I()
	a=li()
	i=0
	s=0
	if(a[i]>0):
		f=1 
	else:
		f=0
	while(i<n):
		if(f):
			j=i 
			k=a[i]
			while(j<n and a[j]>0):
				k=max(k,a[j])
				j+=1 
			s+=k 
			#print(k)
			f=0 
		else:
			j=i 
			k=a[i]
			while(j<n and a[j]<0):
				k=max(a[j],k)
				j+=1 
			s+=k 
			f=1
			#print(k)
		i=j
	print(s)
			
		

	
for _ in range(int(input())):
	case()