n=int(input())
def sign(a):
	return 1 if int(a)>0 else -1

for i in range(n):
	a=int(input())
	arr=raw_input()
	arr=arr.split()
	outer=0
	inner=0
	total=0
	s=sign(arr[0])
	while(outer<len(arr)):
		inner=outer
		m=int(arr[inner])
		while(inner<len(arr) and s==sign(arr[inner])):
			m=max(m,int(arr[inner]))
			inner+=1
		total+=m
		s*=(-1)
		outer=inner
	print(total)

			
