t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]

	sign = []

	temp = [arr[0]]
	for i in range(n-1):
		if arr[i]*arr[i+1] < 0:
			temp.sort()
			sign += [temp[:]]
			temp = [arr[i+1]]
		else:
			temp += [arr[i+1]]

	temp.sort()
	sign += [temp[:]]

	# print(*sign)

	ans = 0
	for x in sign:
		ans += x[-1]

	print(ans)

