def f(a):
	cumul , cur = 0,[1,0]

	for e in a:
		if cur[0] == e / abs(e): cur[1] = max(cur[1], e)
		else:
			cumul += cur[1]
			cur = [ e/abs(e), e]
	cumul += cur[1] if cur[0] == a[-1] / abs(a[-1]) else 0  
	return cumul #sum([e[1] for e in stack])

for t in range(int(raw_input())):
	n,a = int(raw_input()),  map(int,raw_input().split(' '))
	print f(a)