
for __ in range(int(input())):
	n = int(input())
	a = list(map(int,input().split()))
	s = 0
	neg, pos = False, False 
	n, m =[], []
	for i in a:
		if i<0:
			n.append(i)
			neg = True
			if pos == True:

				s += max(m)

				m = []
				pos = False
		if i>0:
			m.append(i)
			pos = True
			if neg == True:

				s += max(n)

				n = []
				neg = False
	if m!=[]:
		s += max(m)
	if n!=[]:
		s+= max(n)
	print(s)
	
