# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	maxxK = 1
	prev = -1
	ans = 0
	minn,maxx = -maxsize,-maxsize
	pos,neg = 0,0
	if(l[0] > 0):
		prev = 1
		pos += 1
		maxx = l[0]
	else:
		neg += 1
		minn = l[0]
	f = 0
	for i in range(1,n):
		f = 1
		if(l[i] > 0):
			pos += 1
			if(prev == -1):
				# print("*")
				f = 0
				maxxK += 1
				prev = 1
				ans += minn
				maxx = l[i]
				minn = -maxsize
			else:
				maxx = max(maxx,l[i])
		else:
			neg += 1
			if(prev == 1):
				# print("2..*")
				f = 0
				maxxK += 1
				prev = -1
				ans += maxx
				minn = l[i]
				maxx = -maxsize
			else:
				minn = max(minn,l[i])
		# print('i:',i,'::','minn:',minn,'maxx:',maxx,'->',ans)
		# print(maxxK)
	if(pos == 0):
		# print('#')
		return max(l)
	elif(neg == 0):
		# print('^')
		return max(l)
		# print(minn,maxx)
	# print('ans:',ans,minn,maxx)
	if(prev == 1):
		# print('1..')
		ans += maxx
	else:
		# print('2...')
		ans += minn
	# print('maxxK:',maxxK)
	return ans

T = int(input())
for _ in range(T):
	N = int(stdin.readline())
	l = list(map(int, stdin.readline().rstrip().split()))
	print(solve(l))

