import math
t=int(input())
for i in range(t):
	n=int(input())
	l=list(map(int,input().split()))
	m=[l[0]]
	s=0
	for i in range(n-1):
		if l[i]*l[i+1]>0:
			m.append(l[i+1])
		else:
			s+=max(m)
			m=[l[i+1]]
	s+=max(m)
	print(s)
