import math

t = int(input())
while t:
	t-=1
	n = int(input())
	a = list(map(int, input().split()))
	flag = 0
	total = 0

	for i in range(len(a)):
		if a[i] < 0:
			if flag == 0:
				s = -math.inf
			elif flag == 1:
				total+=s
				s = -math.inf
			if a[i] > s:
				s = a[i]
			flag = 2
		
		elif a[i] > 0:
			if flag == 0:
				s = -math.inf
			elif flag == 2:
				total+=s
				s = -math.inf
			if a[i]>s:
				s = a[i]
			flag = 1
	total+=s
	print(total)
