def same(num1,num2):
	return (num1 ^ num2) >= 0

t=int(input())


for i in range(t):

	n = int(input())
	arr=[int(x) for x in input().split(" ")]
	ans=[0]*n
	ans[0]=arr[0]
	curr=arr[0]
	for i in range(1,len(arr)):
		if(same(arr[i],curr)):
			if(arr[i]> curr):
				ans[i]=arr[i]
				curr=arr[i]
			else:
				ans[i]=ans[i-1]

		else:
			ans[i]=ans[i-1]+arr[i]
			curr=arr[i]

	print(ans[-1])









