import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(int(input())):
	n = int(input())
	# a,b = map(int,input().split())
	l = list(map(int,input().split()))
	temp = [l[0]]
	for i in range(1,n):
		if (l[i]>0 and temp[-1]>0) or (l[i]<0 and temp[-1]<0):
			temp[-1] = max(temp[-1],l[i])
		else:
			temp.append(l[i])
	print(sum(temp))
	