# Anuneet Anand

T = int(input())

def f(x):
	if x>0:
		return 1
	else:
		return 0

while T:
	n = int(input())
	A = list(map(int,input().split()))
	S = A[0]
	P = A[0]
	F = f(A[0])
	i = 1
	while i<n:
		if f(A[i])!=F:
			F = f(A[i])
			S = S + A[i]
			P = A[i]
		else:
			S = S - P
			P = max(P,A[i])
			S = S + P
		i = i + 1
	print(S)
	T = T - 1