for _ in range(int(input())):
	l=int(input())
	arr=list(map(int,input().split()))
	pos=0;nev=-9999999999;finalsum=0
	for i in range(l):
		if arr[i]>0:
			if i<l-1 and arr[i+1]>0:
				if arr[i]>pos:
					pos=arr[i]
			elif i<l-1 and arr[i+1]<0:
				if arr[i]>pos:
					pos=arr[i]
					# print("number added ",pos)
					finalsum=pos+finalsum
					pos=0
				else:
					finalsum=pos+finalsum
					pos=0
			else:
				if arr[i]>pos:
					pos=arr[i]
					# print("number added ",pos)
					finalsum=pos+finalsum
					pos=0
				else:
					finalsum=pos+finalsum
					
		else:
			if i<l-1 and arr[i+1]<0:
				if arr[i]>nev:
					nev=arr[i]
					# print("new nev iss",nev)
			elif i<l-1 and arr[i+1]>0:
				if arr[i]>nev:
					nev=arr[i]
					# print("number added ",nev)
					finalsum=nev+finalsum
					nev=-99999999999
				else:
					finalsum=nev+finalsum
					nev=-99999999999					
			else:
				if arr[i]>nev:
					nev=arr[i]
					# print("number added ",nev)
					finalsum=nev+finalsum
				else:
					finalsum=nev+finalsum
	print(finalsum)