t = int(input())

for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = []
	indice = 0
	c = []
	
	while(indice < n):
		c.append(a[indice])
		if indice<n-1:
			if a[indice]*a[indice+1]<0:
				b.append(a[indice])
				indice = indice+1
				c = []
			else:
				indice_fisso = indice
				indice = indice+1
				while(indice<=n-1):
					if a[indice_fisso]*a[indice]<0:
						break
					c.append(a[indice])
					indice = indice+1
				b.append(max(c))
				c = []
		else:
			b.append(a[n-1])
			break
	print(sum(b))
