import math

def sign(a):
	if a<0:
		return -1
	return 1
t=int(input())

for tt  in range(t):
	n=int(input())
	arr=list(map(int,input().split()))
	i=0
	ans=0
	while i<len(arr):
		j=i 
		mm=-10000000000
		while j<len(arr) and sign(arr[i])==sign(arr[j]):
			mm=max(arr[j],mm)
			j+=1
		i=j 
		ans+=mm
	print(ans)