for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().split()))
	pre=True
	i=0
	s=0
	while i<n:
		t=-1000000000
		if a[i]<0:
			
			while i<n and a[i]<0:
			
				t=max(t,a[i])
				i+=1
			s+=t
		else:
			
			while i<n and a[i]>0:
				t=max(t,a[i])
				i+=1
				
			s+=t
	print(s)
			
			
				
			
		
			
			
 
