/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int t = sc.nextInt();
		for (int i_=1; i_<=t; i_++)
		{
		    int n= sc.nextInt();
		    int a[]= new int [n];
		    for (int i=0;i<n;i++)
		    {
		        a[i]=sc.nextInt();
		    }
		   
		    long sp=0;
		    int lp=0;
		    long sn=0;
		    int ln=0;
		    if (a[0]>0){
		        sp = a[0];
		        lp=1;
		    }
		    else{
		        sn = a[0];
		        ln=1;
		    }

		    for (int i=1;i<n;i++)
		    {
		        if (a[i]>0)
		        {

		            if (ln+1>lp){
		                lp=ln+1;
		                sp = sn+a[i];
		            }
		            else if(ln+1==lp)
		            {
		                sp = Math.max(sp,sn+a[i]);
		            }
		            
		        }
		        else
		        {

		            if (lp+1>ln){
		                ln=lp+1;
		                sn = sp+a[i];
		            }
		            else if(lp+1==ln)
		            {
		                sn = Math.max(sn,sp+a[i]);
		            }
		        }
		    }
		    if (lp>ln){
		        System.out.println(sp);
		    }
		    else if(ln>lp){
		        System.out.println(sn);
		    }
		    else
		        System.out.println(Math.max(sp,sn));
		    
		}
	}
	static class Scanner 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public Scanner() 
        { 
            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; 
        } 
    } 
}
