t = int(input())
for rep in range(t):
	n = int(input())
	a = list(map(int,input().split()))
	f = -1
	maxi = 0
	s = 0
	for i in range(n):
		if f==-1:
			if a[i] > 0:
				maxi = a[i]
				f = 1
			else:
				maxi = a[i]
				f = 0
		elif f==1:
			if a[i] > 0:
				if a[i] > maxi:
					maxi = a[i]
			else:
				s += maxi
				maxi = a[i]
				f = 0
		elif f==0:
			if a[i] < 0:
				if a[i] > maxi:
					maxi = a[i]
			else:
				s += maxi
				maxi = a[i]
				f = 1
	s += maxi
	print(s)