#python3 
def sol(l):
	dp = [0]*(len(l)+1)
	i,j = 0,0
	count = 0
	while(j <= len(l)-1):
		count += 1
		dp[count] = l[i]
		j = i+1
		while (j <= len(l)-1):
			if (l[i]*l[j] < 0):
				i = j
				break
			else:
				dp[count] = max(l[j], dp[count])
				j += 1
	return print(sum(dp))

t = int(input())
for _ in range(t):
	i = int(input())
	l = list(map(int, input().split()))
	sol(l)



			

