import sys
import math
from math import *
from collections import defaultdict
import os
from io import BytesIO, IOBase
from collections import deque
def check(d):
	if list(d.keys()) == ['a','b','c']:
		if d['a'] == d['c'] or d['b'] == d['c']:
			return True
	return False

def main(d):
	
	n = int(input())
	arr = list(map(int , input().split()))
	res = []
	i = 0
	while(i <n):
		temp = [0]
		while (i<n):
			if arr[i] <0:
				break
			temp.append(arr[i])
			i += 1
		res.append(temp)
		temp = []
		while(i<n):
			if arr[i] >=0:
				break
			temp.append(arr[i])
			i +=1
		if len(temp)>0:
			res.append(temp)

	sum = 0
	for i in res:
		sum += max(i)
	print(sum)

d = defaultdict(lambda:0)
for i in range(int(input())):
	main(d)