import math
test = int(input())

def pos(arr, n):
	pos_ind = -1
	for i in range(n):
		if arr[i] > 0:
			pos_ind = i
			break

	res = []
	if (pos_ind > -1):
		res.append(arr[pos_ind])
		for i in range(pos_ind + 1, n):
			if res[-1] > 0:
				if (arr[i] > 0 and arr[i] > res[-1]):
					res[-1] = arr[i]
				elif(arr[i] < 0):
					res.append(arr[i])
			else:
				if (arr[i] < 0 and arr[i] > res[-1]):
					res[-1] = arr[i]
				elif(arr[i] > 0):
					res.append(arr[i])
	return res

def neg(arr, n):
	neg_ind = 0
	for i in range(n):
		if arr[i] < 0:
			neg_ind = i
			break

	res = []
	res.append(arr[neg_ind])
	for i in range(neg_ind + 1, n):
		if res[-1] > 0:
			if (arr[i] > 0 and arr[i] > res[-1]):
				res[-1] = arr[i]
			elif(arr[i] < 0):
				res.append(arr[i])
		else:
			if (arr[i] < 0 and arr[i] > res[-1]):
				res[-1] = arr[i]
			elif(arr[i] > 0):
				res.append(arr[i])
	return res
  
while test:
	number = int(input())
	arr = list(map(int, input().split()))
	pa = pos(arr, number)
	na = neg(arr, number)
	if len(pa) > len(na):
		print (sum(pa))
	elif(len(pa) < len(na)):
		print(sum(na))
	else:
		print (max(sum(na), sum(pa)))

	test -= 1