# your code goes here


def max_sum(a):
	i = 0
	sum = 0
	
	while i < len(a):
		maxx = 0
		
		# find the largest positive number in this run of positives
		while i <= len(a):
			# run has ended
			if i == len(a) or a[i] < 0:
				#print("adding", maxx)
				sum += maxx
				break
			
			
			maxx = max(a[i], maxx)
			i += 1
		if i == len(a):
			break
		minn = a[i]

		# find the maximum negative number in this run of negatives
		while i <= len(a):
			
			# run has ended
			if i == len(a) or a[i] > 0:
				#print("adding", minn)
				sum += minn
				break
			
			minn = max(a[i], minn)
			i += 1
	return sum

t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(" ")))
	
	print(max_sum(a))
	