t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	m = a[0]
	k = a[0]/abs(a[0])
	for j in range(1,n):
		if k == a[j]/abs(a[j]):
			m = max(m, a[j])
			if j == n-1:
				s+= m
		else:
			s += m
			m = a[j]
			k = a[j]/abs(a[j])
			if j == n-1:
				s+=a[j]
	if n ==1:
		s = m
	print(s)