t = int(input())

while (t):

	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	
	if (a[0] < 0):
		s = -1
	else:
		s = 1
	m = a[0]

	ans = 0

	for i in range(n):
		if (s * a[i] > 0):
			m = max(m,a[i])		
		else:
			ans += m
			m = a[i]
			s *= -1

	ans += m

	print(ans)
		
		
	t -= 1