
import java.util.Scanner;

public class JavaApplication1 {
    
    public static void main(String[] args) {
       int t,n,cnt,current,previous;
       long  d,max,sum;
       Scanner  input=new Scanner(System.in);
       t=input.nextInt();
       long a[]=new long[t];    
       for(int i=0;i<t;i++){
           n=input.nextInt();             
           previous=input.nextInt();
           
           sum=previous;
           cnt=1;
           d=1;
           max=previous;
           for(int k=1;k<n;k++) {
               current=input.nextInt();
               if(previous*current<0){
                   sum+=current;
                   cnt++;              
                                    
               }else{   
                   if(k==1) max=-1;
                   if(max<sum && cnt>1){
                       d=cnt;
                       max=sum;
                   }
                   cnt=1;
                   sum=current;
               }
              
               previous=current;
           }
           
           if(d<cnt) max=sum;
           a[i]=max;
           
       }
       for(int i=0;i<t;i++) System.out.println(a[i]);                
    }
}
    

