for  i in range(int(input())):
	b=int(input())
	a=list(map(int,input().split()))
	r=0
	z=a[0]
	for j in range(1,len(a)):
		if (a[j]>0 and a[j-1]<0) or (a[j]<0 and a[j-1]>0):
			r+=z
			z=a[j]
		else:
			if a[j]>z:
				z=a[j]
	r+=z
	print(r)