import sys

# Fast IO
def input():
	a = sys.stdin.readline()
	if a[-1] == "\n": a = a[:-1]
	return a
def print(*argv):
	n = len(argv)
	for i in range(n):
		if i == n-1: sys.stdout.write(str(argv[i]) + "\n")
		else: sys.stdout.write(str(argv[i]) + " ")
def lcm(x, y):
	from math import gcd
	return (x * y) / (gcd(x, y))

def solve(n, lst):
	if n == 1: return lst[0]
	post = 1
	i = 0
	summ = 0
	while i < n-1:
		maxx = float("-inf")
		if lst[i] > 0 and lst[i+1] > 0:
			for j in range(i, n):
				if lst[j] < 0: break
				else: maxx = max(maxx, lst[j])
			i = j
			summ += maxx
		elif lst[i] < 0 and lst[i+1] < 0:
			for j in range(i, n):
				if lst[j] > 0: break
				else: maxx = max(maxx, lst[j])
			i = j
			summ += maxx
		else:
			summ += lst[i]
			i += 1
	if n >= 2:
		if lst[-1] / lst[-2] < 0:
			summ += lst[-1]
	return summ

for _ in range(int(input())): # Multicase
	n = int(input())
	lst = list(map(int, input().split()))

	print(solve(n, lst))