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

	list_chunk_max = []
	last_e = A[0]
	chunk_max = last_e

	for i in range(1, n):
		if last_e * A[i] > 0:
			chunk_max = max(chunk_max, A[i])
		else:
			list_chunk_max.append(chunk_max)
			chunk_max = A[i]

		last_e = A[i]

	list_chunk_max.append(chunk_max)
	print(sum(list_chunk_max))