from math import *
def main():
	for _ in range(int(input())):
		n=int(input())
		arr=[int(x) for x in input().split()]
		ind=0
		ans=0
		while ind<n:
			if arr[ind]<0:
				loc=arr[ind]
				while arr[ind]<0:
					if ind==n-1:
						loc=max(loc,arr[ind])
						break
					loc=max(loc,arr[ind])
					ind+=1
				ans+=loc
			else:
				loc=arr[ind]
				while arr[ind]>0:
					if ind==n-1:
						loc=max(loc,arr[ind])
						break
					loc=max(loc,arr[ind])
					ind+=1
				ans+=loc
			if ind==n-1:
				if arr[n-1]>0 and arr[n-2]<0:
					ans+=arr[n-1]
				elif arr[n-1]<0 and arr[n-2]>0:
					ans+=arr[n-1]
				print(ans)
				break
main()
