from sys import stdin,stdout
# input = stdin.readline
from math import *
# print = stdout.write
for __ in range(int(input())):
	n=int(input())
	ar=list(map(int,input().split()))
	ans=[ar[0]]
	for i in range(1,n):
		if(ar[i]<0):
			if(ans[-1]<0 and ar[i]>ans[-1]):
				ans[-1]=ar[i]
			elif(ans[-1]>0):
				ans.append(ar[i])
		else:
			if(ans[-1]>0 and ar[i]>ans[-1]):
				ans[-1]=ar[i]
			elif(ans[-1]<0):
				ans.append(ar[i])
	print(sum(ans))
