for _ in range(int(input())):
	n = int(input())
	m = -1000000000
	ls = [int(x) for x in input().split()]
	s = 0
	i = 0
	while i<n:
		if ls[i]>0:
			while i<n:
				if ls[i]>0:
					m = max(m,ls[i])
					i+=1
				else:
					break
			s+=m
			m= - 1000000000
		else:
			while i < n:
				if ls[i] < 0:
					m = max(m,ls[i])
					i+=1
				else:
					break
			s+=m
			m = -1000000000
	print(s)
			

