# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w') 


for _ in range(int(input())):
	n=int(input())
	li=[int(x) for x in input().split()]

	neg=0
	pos=0
	ans=-1e18

	k=0
	size=0
	for i in li:
		if(i<0 and k==0):
			ans = ans+i
			size+=1
			k=1
			neg=i
		elif(i<0 and k==1):
			ans =  max(ans, i+pos)
			neg=max(neg, i)

		elif(i>0 and k==1):
			ans = ans+i
			size+=1
			k=0
			pos=i
		else:
			ans=max(ans, i+neg)
			pos=max(pos, i)
	print(ans)