t = int(input())
for u in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	ma = 0
	summ = 0
	curr = -1
	for i in range(n):
		if a[i] > 0 and curr != 1:
			curr = 1
			summ += ma
			ma = a[i]
		elif a[i] < 0 and curr != 0:
			curr = 0
			summ += ma
			ma = a[i]
		elif a[i] > 0 and curr == 1:
			ma = max(ma,a[i])
		elif a[i] < 0 and curr == 0:
			ma = max(ma,a[i])
	summ += ma
	print(summ)