#                                               |
#   _` |  __ \    _` |   __|   _ \   __ \    _` |   _` |
#  (   |  |   |  (   |  (     (   |  |   |  (   |  (   |
# \__,_| _|  _| \__,_| \___| \___/  _|  _| \__,_| \__,_|

import sys
import math
from collections import deque
import random 

def read_line():
	return sys.stdin.readline()[:-1]
 
def read_int():
	return int(sys.stdin.readline())
	
def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def power(x, y, p) : 
	res = 1
	x = x % p  
	  
	if (x == 0) : 
		return 0
  
	while (y > 0) : 
		if ((y & 1) == 1) : 
			res = (res * x) % p 
 
		y = y >> 1
		x = (x * x) % p 
		  
	return res   

t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	if a[0]>0:
		sign = 1
	else:
		sign = 0
	m = a[0]
	s = 0
	ele = []
	for i in range(1,n):
		if a[i]>0 and sign == 1:
			m = max(m,a[i])

		elif a[i]>0 and sign == 0:
			s += m
			ele.append(m)
			m = a[i]
			sign = 1

		if a[i]<0 and sign == 0:
			m = max(m,a[i])

		elif a[i]<0 and sign == 1:
			s += m
			ele.append(m)
			m = a[i]
			sign = 0

	ele.append(m)
	s = sum(ele)
	print(s)

	



