for _ in range(int(input())):
	n=int(input())
	a = [int(x) for x in input().split()]
	i,ans = 0,0
	while i < n:
		j = i+1
		mx = a[i]
		while j < n:
			if (a[i]>0 ^ a[j]>0):
				mx = max(mx,a[j])
				j += 1
			else:
				break
		i = j
		ans += mx
	print(ans)