from sys import stdin,stdout
for _ in range(int(stdin.readline())):
	input()
	a=list(map(int,stdin.readline().split()))
	s=0;m=a[0]
	for v in a:
		if m*v<0:
			s+=m
			m=v
		m=max(m,v)
	s+=m
	stdout.write(str(s)+'\n')