import math
t=int(input())
for g in range(0,t):
    n=int(input())
    a=list(map(int,input().split()))
    sum=0
    i=0
    if(a[0]>0):
        while(i<n):
            b=[]
            while(i<n and a[i]>0 ):
                b.append(a[i])
                i=i+1
            sum+=max(b)
            if(i>n-1):
                break
            b=[]
            while(i<n and a[i]<0):
                b.append(a[i])
                i=i+1
            sum+=max(b)
            if(i>n-1):
                break
    else:
        while(i<n):
            b=[]
            while(i<n and a[i]<0):
                b.append(a[i])
                i=i+1
            sum+=max(b)
            if(i>n-1):
                break
            b=[]
            while(i<n and a[i]>0):
                b.append(a[i])
                i=i+1
            sum+=max(b)
            if(i>n-1):
                break
    print(sum)
            

        
    
   
    
    
    
    
                
    
                

        