for _ in range(int(input())):
	n = int(input())
	arr = list(map(int,input().split()))
	new=[arr[0]]
	p=1 if arr[0]>0 else 0
	for i in range(1,n):
		if p^(arr[i]>0):
			p^=1
			new.append(arr[i])
		else:
			new[-1]=max(new[-1],arr[i])
	print(sum(new))