for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	p=[0]*n
	flag=0
	if l[0]<0:
		flag=-1
	else:
		flag=1
	mi=-99999999999999999
	ma=-99999999999999999
	s=0
	for x in range(0,n):
		if flag==1 and l[x]>0:
			mi=max(mi,l[x])
		elif flag==-1 and l[x]<0:
			ma=max(ma,l[x])
		elif flag==1 and l[x]<0:
			s+=mi
			mi=-9999999999999999
			ma=l[x]
			flag=-1
		elif flag==-1 and l[x]>0:
			s+=ma
			ma=-9999999999999999
			mi=l[x]
			flag=1
	if flag==-1:
		s+=ma
	else:
		s+=mi
	print(s)