
for i in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	summ=0
	keep=l[0]
	for i in range(n-1):
		if(l[i]*l[i+1])<0:
			summ+=keep
			keep=l[i+1]
		else:
			if(l[i+1]>keep):
				keep=l[i+1]
			
		
	print(summ+keep)