for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().split()))
	k=a[0]
	if k>0:
		p=0
		b=[]
		i=0
		while i<len(a):
			while i!=len(a) and a[i]>0 :
				b.append(a[i])
				i+=1
			if len(b)!=0:
			#	print(b)
				p+=max(b)
				b.clear()
			if i==len(a):
				break
			while i!=len(a) and a[i]<0:
				b.append(a[i])
				i+=1
			if len(b)!=0:
			#	print(b)
				p+=max(b)
				b.clear()
	else:
		p=0
		b=[]
		i=0
		while i<len(a):
			while i!=len(a) and  a[i]<0:
				b.append(a[i])
				i+=1
			if len(b)!=0:
			#	print(b)
				p+=max(b)
				b.clear()
			if i==len(a):
				break
			while i!=len(a)  and a[i]>0 :
				b.append(a[i])
				i+=1
			if len(b)!=0:
			#	print(b)
				p+=max(b)
				b.clear()
	print(p)
			
			
				
				
		
				
	
	
		