test = int(input())
for t in range(test):

	n = int(input())
	l = list(map(int,input().split(' ')))
	l1 = []
	lapp=[l[0]]
	it = l[0]
	for i in range(1,len(l)):
		if( it * l[i] > 0):
			lapp.append(l[i])
			it = l[i]
		else:
			# print(lapp)
			l1.append(lapp)
			lapp = [l[i]]
			it = l[i]
	l1.append(lapp)
	s = 0
	for i in range(len(l1)):
		s += max(l1[i])
	print(s)