# your code goes here
t = int(input())
for i in range(t):
	n = int(input())
	arr = input().split(" ")
	for j in range(n):
		arr[j] = int(arr[j])
	max = arr[0]
	sum = 0
	for j in range(1,n):
		if arr[j]*arr[j-1] > 0:
			if arr[j] > max: 
				max = arr[j]
		else:
			sum = sum + max
			max = arr[j]
	sum = sum + max
	print(sum)
