import sys 
try:
    sys.stdin = open('input.txt', 'r') 
    sys.stdout = open('output.txt', 'w')
except:
    pass

input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int,input().split()))
	poslen = 0
	neglen = 0
	possum = 0
	negsum = 0
	ind = 0
	pflag = 'p'
	nflag = 'n'
	ps = 0
	ns = 0
	nlocal = -float('inf')
	plocal = 0
	for ind in range(n):
		if l[ind] < 0: #negative
			if pflag == 'p' and ps:
				poslen += 1 
				possum += plocal
				plocal = l[ind]
				pflag = 'n'
			elif pflag == 'n' and ps:
				plocal = max(plocal,l[ind])
			if nflag == 'n':
				ns = 1
				nlocal = max(l[ind],nlocal)
				# print("nlocal ",nlocal)
			else:
				neglen += 1
				negsum += nlocal
				# print('nsum ',negsum)
				nlocal = l[ind]
				# print(nlocal,' nlocal')
				nflag = 'n'
		else:
			if pflag == 'n':
				poslen += 1
				possum += plocal
				plocal = l[ind]
				pflag = 'p'
			else:
				ps = 1
				plocal = max(plocal,l[ind])
				
			if nflag == 'n' and ns:
				neglen += 1
				negsum += nlocal 
				# print('nsum ',negsum)
				nlocal = l[ind]
				# print(nlocal,' nlocal')
				nflag = 'p'
			elif nflag == 'p' and ns:
				nlocal = max(nlocal,l[ind])
				# print('nlocal',nlocal)
	if ps == 1:	
		poslen += 1
	if ns == 1:
		neglen += 1
	possum += plocal
	negsum += nlocal
	# print(neglen,negsum)
	# print(poslen,neglen,possum,negsum)
	if poslen>neglen:
		print(possum)
	elif neglen>poslen:
		print(negsum)
	else:
		print(max(possum,negsum))


	
