t = int(input())
for test in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a.append(0)
	ans = 0
	i = 0
	while i < n:
		m = a[i]
		while ((a[i]>0) == (a[i+1]>0)) and i < n-1:
			m = max(m, a[i+1])
			i += 1
		ans += m
		i += 1
	print(ans)