import java.util.*;
public class JavaApplication148 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
     int t=sc.nextInt();
   while(t--!=0){
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        int maxp=Integer.MIN_VALUE,maxn=Integer.MIN_VALUE;
        long sum=0;
        int count1=0,count2=0;
        boolean flag=true;
        for(int i=0;i<n;i++)
        {
            while(i<n&& a[i]>0)
            {
                if(a[i]>maxp)
                    maxp=a[i];
                i++;
                count1++;
                if(count1==n)
                { flag=false;
                    break;
                }
           
            }
            while(i<n&& a[i]<0)
            {
                if(a[i]>maxn)
                    maxn=a[i];
                i++;
                count2++;
                if(count2==n)
                {
                    flag=false;
                    break;
                }
            }
            if(maxn==Integer.MIN_VALUE)
                maxn=0;
            else if(maxp==Integer.MIN_VALUE)
                maxp=0;
            sum=sum+maxn+maxp;
           // System.out.println("i"+i);
            i--;
             maxp=Integer.MIN_VALUE;
             maxn=Integer.MIN_VALUE;
            
        }
        if(flag==false)
            System.out.println(-1);
        else
        System.out.println(sum);
        


   }
      
       
        
    }
    
}