t = int(input())
for _ in range(t):
	n = int(input())
	li = list(input().split())
	curr = int(li[0])
	sum = 0
	x = 0
	for i in range(1,n):
		x = curr * int(li[i])
		if(x > 0):
			curr = max(curr, int(li[i]))
		else:
			sum  = sum + curr
			curr = int(li[i])
	sum = sum + curr
	print(sum)		
