
t=int(input())
for i in range(t):
	n= int(input())
	l=list(map(int,input().split()))
	a=[]
	for j in range(n):
		if(j==0):
			a.append(l[j])
		elif((a[-1]<0 and l[j]>0) or (a[-1]>0 and l[j]<0)):
			a.append(l[j])
		elif((a[-1]<0 and l[j]<0 and l[j]>a[-1]) or (a[-1]>0 and l[j]>0 and l[j]>a[-1])):
			a[-1]=l[j]
	print(sum(a))
