from sys import*
def sum_seq(a,n):
	sign = None
	max = 0
	min = 0
	sum = 0
	for i in range(n):
		if(sign == None):
			if(a[i] > 0):
				sign  = "pos"
				max = a[i]
			else:
				sign = "neg"
				min = a[i]
		else:
			if((sign == "pos") and a[i] > 0):
				if(a[i] > max):
					max = a[i]
			elif((sign == "pos") and a[i] < 0):
				sum = sum + max
				max = 0
				min = a[i]
				sign = "neg"
			elif((sign == "neg") and a[i] < 0):
				if(a[i] > min):
					min = a[i]
			else:
				sum = sum + min
				min = 0
				max = a[i]
				sign = "pos"
	sum = sum + max + min
	return sum
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int,input().strip().split()))[:n]
	x = sum_seq(a,n)
	print(x)