t = int(input())

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

	prev = arr[0]
	ans = 0

	for elem in arr[1:]:
		if (prev^elem <0):
			ans += prev
			prev = elem
		else:
			if (elem>prev):
				prev = elem

	ans += prev
	print(ans)