import math as m
def f1():
	T=int(input())
	#while(T!=0):
#		T=T-1
#		N=int(input())
		#pass

def f3():
	T=int(input())
	while(T!=0):
		T=T-1
		N=int(input())
		Arr=[int(i) for i in input().split(" ")]
		ans=0
		mx=-1e11
		flag=False
		for i in range(0,len(Arr)):
			if(i>0):
				#print(mx)
				if(Arr[i-1]<0 and Arr[i]>0):
					ans=ans+mx
					mx=-1e11
					flag=True
				elif(Arr[i-1]>0 and Arr[i]<0):
					ans=ans+mx
					mx=-1e11
					flag=True
			if(mx<Arr[i]):
				mx=Arr[i]
			if(i==len(Arr)-1):
				ans=ans+mx
		print(ans)

def f2():
	T=int(input())
	while(T!=0):
		T=T-1
		n=int(input())
		if((n//2)%2!=0):
			print("NO")
		else:
			E=[2*i for i in range(1,(n//2)+1)]
			O=[i for i in range(1,n-1,2)]
			se=sum(E)
			so=sum(O)
			O.append(se-so)
			print("YES")
			for i in E:
				print(i,end=" ")
			for i in O:
				print(i,end=" ")
			print()



	#Arr=[int(i) for i in input().split()]


if __name__ == '__main__':
	f3()

