def signof(i):
	if i<0:
		return -1
	if i>0:
		return 1

for _ in  range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	maxsum = 0
	i = 0
	while i<n:
		current = a[i]
		j = i
		while j<n and signof(a[i]) == signof(a[j]):
			current = max(current,a[j])
			j += 1
		maxsum += current
		i = j
	print(maxsum)
