/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class hrg
{
    static void shuffle( int arr[], int n)
    {
        // Creating a object for Random class
        Random r = new Random();
         
        // Start from the last element and swap one by one. We don't
        // need to run for the first element that's why i > 0
        for (int i = n-1; i > 0; i--) {
             
            // Pick a random index from 0 to i
            int j = r.nextInt(i+1);
             
            // Swap arr[i] with the element at random index
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        // Prints the random array
       // System.out.println(Arrays.toString(arr));
    }
    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[][] tdiarr(int m , int n){
            int[][] a = new int[m][n];
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    a[i][j]=Integer.parseInt(next());
                }
            }
            return a;
        } 
        int[] niarr(int n)
        {
            int[] a = new int[n];
            for(int i=0;i<n;i++)a[i]=Integer.parseInt(next());
            return a;
        }
        long[] nlarr(int n)
        {
            long[] a = new long[n];
            for(int i=0;i<n;i++)a[i]=Long.parseLong(next());
            return a;
        }
        char[] ncarr(){
            return next().trim().toCharArray();
            
            
        }
        
  
        int ni() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nd() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nstr() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    static FastReader br=new FastReader();//(new InputStreamReader(System.in));
		
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int t=1;
		br=new FastReader();
		t=br.ni();//Integer.parseInt(br.readLine().trim());
		StringBuilder sb=new StringBuilder();
	in1 :	while(t-->0)
		{
		   sb.append(solve());
		   sb.append("\n");
		}
			//			System.out.println("OUTPUT:::");
	
		System.out.println(sb);
	}
	static long solve(){
	    int n = br.ni() ;
	    long[] a = br.nlarr(n);
	    long sum = 0L ;
	    int i =0;
	    if(a[0] > 0L){
	        long max =  Long.MIN_VALUE;
	        while(i<n && a[i]>0){
	            max = Math.max(max,a[i]);
	            i++;
	        }
	        if(max!=Long.MIN_VALUE)sum += max;
	         max = Long.MIN_VALUE;
	        while(i<n && a[i]<0){
	            max = Math.max(max,a[i]);
	            i++;
	        }
	        if(max!=Long.MIN_VALUE)sum += max;
	        
	    }
	    else {
	        long max =  Long.MIN_VALUE;
	        while(i<n && a[i]<0){
	            max = Math.max(max,a[i]);
	            i++;
	        }
	        if(max!=Long.MIN_VALUE)sum += max;
	         max = Long.MIN_VALUE;
	        while(i<n && a[i]>0){
	            max = Math.max(max,a[i]);
	            i++;
	        }
	        if(max!=Long.MIN_VALUE)sum += max;
	        
	        
	    }
	    return sum;
	}
}


