import sys
import math
input = sys.stdin.buffer.readline

for _ in range(int(input())):
	n = int(input())

	a = list(map(int,input().split()))


	pos = True
	if a[0] < 0:
		pos = False

	i=0
	mVal = int(-1e9)
	ar = 0
	while i<n:
		if pos:
			if a[i]>0:
				mVal = max(mVal,a[i])
			else:
				ar += mVal
				mVal = a[i]
				pos = False
		else:
			if a[i]<0:
				mVal = max(mVal,a[i])
			else:
				ar += mVal
				mVal = a[i]
				pos = True
		i+=1
		#print(ar,end=" ")

	ar += mVal 
	print(ar)
