t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int,input().split()))
	main = []
	li = []
	i = 0
	s = 0
	while(i<n):
		if(arr[i]<0):
			while(i<n):
				if(arr[i]>0):
					break
				li.append(arr[i])
				i += 1
			main.append(li)
			li = []
		else:
			while(i<n):
				if(arr[i]<0):
					break
				li.append(arr[i])
				i += 1
			main.append(li)
			li = []
		
	
	for i in main:
		s += max(i)

	print(s)