def altsum(L):
	n=len(L)
	s=0	
	i=0
	j=0
	while(i<n):
		p=L[i]
		while(j<n and L[i]*L[j]>0):
			p=max(p,L[j])
			j+=1			
		s+=p			
		i=j
	return s

t=int(input())
for i in range(0,t):
	n=int(input())
	L=list(map(int,input().split()))
	print(altsum(L))

