for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	s=0
	x,y=[],[]
	for i in range(n):
		if l[i]>0:
			if len(y)>0:s+=max(y);y=[]
			x.append(l[i])
		else:
			if len(x)>0:s+=max(x);x=[]
			y.append(l[i])
	if len(x)>0:s+=max(x)
	if len(y)>0:s+=max(y)
	print(s)