I=lambda: map(int, raw_input().split())
t = input()
for _ in xrange(t):
	n = input()
	a = I()
	curM = a[0]
	if curM > 0:
		pos = True
	else:
		pos = False
	s = 0
	for x in a:
		if pos and x<0:
			pos = False
			s += curM
			curM = x
		elif not pos and x>0:
			pos = True
			s += curM
			curM = x
		else:
			curM = max(x, curM)
	s += curM
	print s
			