t = int(input())

while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]

	seq = []
	pt1 = 0; pt2 = 0
	i = 0; sign = 0

	if a[0] > 0:
		sign = 1
	else:
		sign = -1

	while i < n:
		pt1 = i
		while i < n and sign*a[i] > 0:
			pt2 = i
			i += 1
		seq.append(max(a[pt1:pt2+1]))
		sign = -sign

		# print(pt1, pt2)
	print(sum(seq))
