a=int(input())
for i in range(0,a):
    b=input()
    arr=list(map(int,input().split()))
    count=0
    sign=arr[0]
    maxx=-float('inf')
    minn=maxx
    summ=0
    for i in range(0,len(arr)):
        if(arr[i]>0 and sign<0):
            count=count+1 
            sign=1
            summ=summ+minn
            maxx=arr[i]
            minn=float('inf')
        if(arr[i]<0 and sign>0):
            count=count+1 
            sign=-1
            summ=summ+maxx
            minn=arr[i]
            maxx=float('inf')
        if(arr[i]>0 and sign>0):
            if(arr[i]>maxx):
                maxx=arr[i]
            if(i==len(arr)-1):
                summ=summ+maxx
        if(arr[i]<0 and sign<0):
            if(arr[i]>minn):
                minn=arr[i]
            if(i==len(arr)-1):
                summ=summ+minn
                
            
    print(summ)        
    