import java.util.*;
public class xyz
{
    public static int max(int[] arr, int start , int end)
    {
        int max = Integer.MIN_VALUE;
        
        for( int i = start ; i<= end ; i++)
        {
            if(arr[i] > max)
            {
                max = arr[i];
            }
            
        }
        
        
        
       return max; 
    }
    
    
    public static void main(String[] args)
    {
        Scanner scn = new Scanner(System.in);
       
        int t = scn.nextInt();
         
        for( int j = 1; j<= t ; j++ )
        {
            int n = scn.nextInt() ;
            int[] arr = new int[n];
            
            for(int i= 0; i < n  ; i++)
            {
                
                arr[i] = scn.nextInt();
                
            }
            
            
            int start = 0 ;
            int end = 0;
            long sum = 0 ;
            
            for( int i = 1 ; i < n ; i++)
            {
                if(arr[start]*arr[i] < 0)
                {
                    end = i-1;
                    
                    sum = sum + max(arr,start ,end) ;
                    
                    start = i ;
                }
                
                
            
            }
            
            end = n-1 ; 
            sum = sum +  max(arr,start ,end) ;
            
        System.out.println(sum) ;
        }
    }
    
}
    