t=int(input())
for i in range(t):
	n=int(input())
	arr=list(map(int,input().split()))
	mx=arr[0]
	s=0
	for j in range(n):
		if(arr[j]*mx<0):
			s+=mx
			mx=arr[j]
		else:
			mx=max(mx,arr[j])
	print(s+mx)