

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

public class Main
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static long mod = 1000000007;

  
	public static void main (String[] args) throws java.lang.Exception
	{
	    FastReader sc = new FastReader();
	    
	    int t=sc.nextInt();
	    
	    while(t-->0)
	    {
	    	int n = sc.nextInt();
	    	long a[] = new long[n];
	    	for(int i=0;i<n;i++)
	    		a[i]=sc.nextLong();

	    	long ans=0;
	    	long max=a[0];
	    	for(int i=1;i<n;i++)
	    	{
	    		
	    		if(a[i]>=0 && a[i-1]>=0)
	    		{
	    			if(max<a[i])
	    				max=a[i];
	    			if(i==n-1)
	    				{ans = ans+max;
	    				}

	    	//System.out.println(ans+" "+max+" "+i);}
	    		}
	    		else if(a[i]<0 && a[i-1]<0)
	    		{
	    			if(max<a[i])
	    				max=a[i];


	    			if(i==n-1)
	    				{ans = ans+max;
	    				}

	    	//System.out.println(ans+" "+max+" "+i);}
	    		}
	    		else
	    		{

	    //	System.out.println(ans+" "+max+" "+i);
	    			ans = ans+max;
	    			
	    			max=a[i];

	    			if(i==n-1)
	    				ans = ans+max;

	    		}
	    		
	    	}

	    	System.out.println(ans);
         
	        
        }
	}
	
	
}
