case = int(input())
for n in range(case):
	n = int(input())
	a = list(map(lambda x : int(x), input().split()))
	goal = []
	s = 0
	goal.append(a[0])
	for i in range(1,n):
		if a[i] * a[i-1] < 0:
			s = s + max(goal)
			goal = []
		goal.append(a[i])
	s = s + max(goal)
	print(s)