#two pointer approch
for _ in range(int(input())):
	x = int(input())
	*li, = map(int, input().split())
	ans, i  = 0, 0
	while i <x:
		sum1 = li[i]
		j = i
		while j<x and (li[i]*li[j] > 0):
			sum1 = max(sum1, li[j])
			j += 1
		ans += sum1
		i = j
	
	print(ans)