for _ in range(int(input())):
	n= int(input())
	arr = list(map(int,input().split()))
	i=su=cr=0
	k=-(2*(10**5)+1)
	maxi=k
	flag=True
	while i<n:
		cur=arr[i]
		j=i
		while j<n and cur*arr[j]>0:
			cur = max(cur,arr[j])
			j+=1
		su+=cur
		i=j
	print(su)