def checkl(a,i):
	p=a[i]
	x=i
	while(x<len(a) and a[x]*a[i]>0):
		p=max(p,a[x])
		x+=1
	return [p,x]

for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().split()))
	k=0
	ans=0
	while(k!=len(a)):
		r,s=checkl(a,k)
		ans+=r
		k=s
	print(ans)