t = int(input())

for i in range(t):
	n = int(input())

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

	curr_sum = 0

	if nums[0]<0:
		curr_sign = 1

	cur_num = nums[0]

	done = False

	for i1 in range(n):
		# print(curr_sum, cur_num, "b")
		i = nums[i1]
		if i/cur_num > 0:
			if i > cur_num:
				cur_num = i

		else:
			curr_sum += cur_num
			cur_num = i

			if i1 == n-1:
				curr_sum += i
				done = True
		# print(curr_sum, cur_num, "a", done)

	if not done:
		curr_sum += cur_num

	print(curr_sum)