t = int(input())

for i in range(t):

	n = int(input())

	nums = list(map(int,input().split()))

	l = 0
	r = 1
	output = []
	while l<len(nums):
		while r < n and nums[l]*nums[r]>0:
			r +=1

		output.append(max(nums[l:r]))

		l =r
		r += 1

	print(sum(output))