import sys

#list(map(int, sys.sdtin.readline().split()))
#map(int, sys.sdtin.readline().split())

t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	array = list(map(int, sys.stdin.readline().split()))
	if array[0] > 0:
		signe = 1
	else:
		signe = -1
	maxi = -10**9
	somme = 0
	for i in range(n):
		
		if signe == 1 and array[i] < 0:
			signe = -1
			somme += maxi
			maxi = -10**9
		if signe == -1 and array[i] > 0:
			signe = 1
			somme += maxi
			maxi = -10**9
		maxi = max(maxi, array[i])
		#print(somme, maxi)
	somme += maxi
	print(somme)