def dp(arr,n,i,status):
	i=0
	ans=0
	while(i<n):
		max1=float("-inf")
		max2=float("-inf")
		if(arr[i]<0):
			while(i<n and arr[i]<0):
				max1=max(arr[i],max1)
				i+=1
			while(i<n and arr[i]>0):
				max2=max(arr[i],max2)
				i+=1
		else:
			while(i<n and arr[i]>0):
				max2=max(arr[i],max2)
				i+=1
			while(i<n and arr[i]<0):
				max1=max(arr[i],max1)
				i+=1
		if(max1==float("-inf")):
			max1=0
		if(max2==float("-inf")):
			max2=0
		ans+=max1+max2
	return ans;






t=int(input())

for _  in range(t):
	n=int(input())
	arr=list(map(int,input().split()))
	print(dp(arr,n,0,-1))
