for _ in range(int(input())):
	n = int(input())
	l = list(map(int,input().split()))
	ans=0
	negmx=-1*1e9
	posmx=-1*1e9
	for i in range(0,n):
		if i!=0:
			if l[i]>=0 and l[i-1]<0:
				# print(i,negmx)
				ans+=negmx
				negmx=-1e9
				posmx=-1e9
			elif l[i]<0 and l[i-1]>=0:
				# print(i,posmx)
				ans+=posmx
				negmx=-1e9
				posmx=-1e9
		if l[i]<0:
			negmx=max(negmx,l[i])
		else:
			posmx=max(posmx,l[i])
	if(l[n-1]<0):
		ans+=negmx
	else:
		ans+=posmx
	print(int(ans))
