t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(i) for i in input().split(' ')]
	j = 0
	sum = 0
	while j < len(s):
		i = j
		cur_elem = s[i]
		while j < len(s) and s[i] * s[j] > 0:
			cur_elem = max(s[j], cur_elem)
			j += 1
		sum += cur_elem
	
	print(sum)