t = int(input())
for k in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	temp = arr[0]
	sign = 0
	s = 0
	last = arr[0]/abs(arr[0])
	for i in range(1,n):
		if (arr[i]<0 and arr[i-1]>0) or (arr[i]>0 and arr[i-1] < 0):
			s+=temp
		if arr[i]<0:
			if last > 0:
				temp = arr[i]
			else:
				temp = max(temp, arr[i])
			last = -1
		elif arr[i]>0:
			if last < 0:
				temp = arr[i]
			else:
				temp = max(temp, arr[i])
			last = 1
	print(s+temp)