for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	maxi=l[0]
	ans=0
	for i in range(1,n):
		if (l[i-1]>0 and l[i]<0) or (l[i-1]<0 and l[i]>0):
			ans+=maxi
			maxi=l[i]
			continue
		maxi=max(l[i],maxi)
	ans+=maxi
	print(ans)