import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
 
public class Solution 
{ 
    
    public static void main(String[] args) throws IOException 
    { 
  
       BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in));
                               int t = Integer.parseInt(br.readLine());
            while(t-->0)    {
               int n = Integer.parseInt(br.readLine());
                
          
                 
                  long[]a=new long[n];
                StringTokenizer sa1=new StringTokenizer(br.readLine());
                  for(int i=0;i<n;i++)
                  {   
                        a[i] = Long.parseLong(sa1.nextToken());
                    
            
                  }
                 
                   int sign=(a[0]>0)?1:-1;long sum=0;long sa=a[0];
                   for(int i=1;i<n;i++){
                       
                       while(i<n){
                         int  s=(a[i]>0)?1:-1;
                           if(s!=sign)break;
                           sa=Math.max(sa,a[i]);
                           i++;
                   }
                  // System.out.println(i+" "+(sign)+" "+sa);
                   sum+=sa;
                   
               if(i==n)
                   break;
                   sa=a[i];
                   sign*=-1;
                  
                    while(i<n){
                         int  s=(a[i]>0)?1:-1;
                           if(s!=sign)break;
                            sa=Math.max(sa,a[i]);
                           i++;
                   }
                 //   System.out.println(i+" "+(sign)+" "+sa);
                   sum+=sa;
                    if(i==n)
                   break;
                   sa=a[i];
                 sign*=-1;
                  
            }
            System.out.println(sum);
            
            }   
                
                     
    }
    }