t=int(input())
for _ in range(t):
	n=int(input())
	l=list(map(int,input().split()))
	ind=0
	ans=0
	while(ind<len(l)):
		mx=0
		mn=-99999999999
		if(l[ind]>0):
			while(ind<len(l) and l[ind]>0):
				if(mx<l[ind]):
					mx=l[ind]
				ind+=1
			ans+=mx
			# print("mx",mx)
		else:
			while(ind<len(l) and l[ind]<0):
				if(mn<l[ind]):
					mn=l[ind]
				ind+=1
			ans+=mn
			# print("mn",mn)
	print(ans)



