for t in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))

	max_sum = - (10 ** 14)
	max_len = 0

	for j in range(0, n):
		if n - j < max_len:
			break

		last_e = A[j]
		temp_max_len = 1
		temp_max_sum = A[j]

		for i in range(j, n):
			if A[i] * last_e < 0:
				last_e = A[i]
				temp_max_sum += A[i]
				temp_max_len += 1

		if temp_max_len > max_len:
			max_len = temp_max_len
			max_sum = temp_max_sum

		elif temp_max_len == max_len:
			max_sum = max(max_sum, temp_max_sum)

	print(max_sum)

		
			

