t=int(input())
for tt in range(t):
	n=int(input())
	a=list(map(int,input().split(' ')))
	firsts=[0]
	mem=round(a[0]/abs(a[0]))
	for i in range(n):
		if(mem*a[i]<0):
			mem*=-1
			firsts.append(i)
	breaks=[]
	for i in range(len(firsts)-1):
		breaks.append(a[firsts[i]:firsts[i+1]])
	breaks.append(a[firsts[-1]:len(a)])
	q=0
	for x in breaks:
		q+=max(x)
	print(q)
