def maximum_subsequence(l):
	n=len(l)
	b=[[]]
	b[-1].append(l[0])
	if l[0]>0:
		a=1
	else:
		a=-1
	for i in range(1,n):
		if a==1:
			if l[i]>0:
				b[-1].append(l[i])
			else:
				b.append([l[i]])
				a=-1
		else:
			if l[i]<0:
				b[-1].append(l[i])
			else:
				b.append([l[i]])
				a=1
	s=0
	for j in b:
		s+=max(j)
	return s
def maximum_subsequence1(l):
	n=len(l)
	if l[0]>0:
		a=1
	else:
		a=-1
	g=l[0]
	s=0
	for i in range(1,n):
		if a==1:
			if l[i]>0:
				if l[i]>g:
					g=l[i]
			else:
				s+=g
				g=l[i]
				a=-1
		else:
			if l[i]<0:
				if l[i]>g:
					g=l[i]
			else:
				s+=g
				g=l[i]
				a=1
	return s+g
t=int(input())
for _ in range(t):
	n=int(input())
	l=list(map(int, input().split()))
	print(maximum_subsequence1(l))

