t = int(input())
output = []
for _ in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	
	last_negative = a[0] < 0
	last_number = a[0]
	b = []

	for i in range(0,len(a)):
		if i == len(a) - 1:
			b.append(last_number)
			break
		if last_negative and a[i+1] >= 0:
			last_negative = False
			b.append(last_number)
			last_number = a[i+1]
		elif last_negative and a[i+1] < 0 and a[i+1] > last_number:
			last_number = a[i+1]
		elif not last_negative and a[i+1] < 0:
			last_negative = True
			b.append(last_number)
			last_number = a[i+1]
		elif not last_negative and a[i+1] >= 0 and a[i+1] > last_number:
			last_number = a[i+1]

	output.append(b)
for o in output:	
	print(sum(o))