t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int,input().split()))
	taken = "P" if arr[0]>=0 else "N"
	temp = []
	temp.append(arr[0])
	for j in range(1,n):
		new_taken = "P" if arr[j] >=0 else "N"
		if taken == new_taken: 
			if arr[j] > temp[-1]:
				temp.pop()
				temp.append(arr[j])
		else:
			temp.append(arr[j])
			taken = "P" if arr[j]>=0 else "N"
	print(sum(temp))
		
