import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right


# Function to call the actual solution
def solution(li, n):
	pos = 0
	neg = 0
	prev = -1
	cur_e = float('-inf')
	flag = False
	for i in range(n):
		if prev < 0 and li[i] > 0:
			flag = True
			cur_e = max(cur_e, li[i])
		elif prev < 0 and li[i] < 0:
			pos += cur_e
			prev = 1
			cur_e = li[i]
		elif prev > 0 and li[i] < 0:
			cur_e = max(cur_e, li[i])
		elif prev > 0 and li[i] > 0:
			pos += cur_e
			prev = -1
			cur_e = li[i]
	pos += cur_e
	if not flag:
		pos = float('-inf')
	prev = 1
	cur_e = float('-inf')
	flag = False
	for i in range(n):
		if prev < 0 and li[i] > 0:
			cur_e = max(cur_e, li[i])
		elif prev < 0 and li[i] < 0:
			neg += cur_e
			prev = 1
			cur_e = li[i]
		elif prev > 0 and li[i] < 0:
			flag = True
			# print("here")
			cur_e = max(cur_e, li[i])
		elif prev > 0 and li[i] > 0:
			neg += cur_e
			prev = -1
			cur_e = li[i]
		# print(neg)
	neg += cur_e
	if not flag:
		neg = float('-inf')
	# print(neg, pos)
	return max(pos, neg)


# Function to take input
def input_test():
	for _ in range(int(input())):
		n = int(input())
		# a, b = map(int, input().strip().split(" "))
		# a, b, c = map(int, input().strip().split(" "))
		li = list(map(int, input().strip().split(" ")))
		out = solution(li, n)
		print(out)

# Function to check test my code
def test():
	pass


input_test()
# test()