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


/*


*/


public class Main {
	static FastReader sc=null;
	
	
	public static void main(String[] args) {
		sc=new FastReader();
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			int a[]=sc.readArray(n);
			long ans=0,max=a[0];
			for(int i=1;i<n;i++) {
				if(sign(a[i],a[i-1]))max=Math.max(a[i], a[i-1]);
				else {
					if(max==Integer.MIN_VALUE)max=a[i-1];
					//System.out.print(max+" ");
					ans+=max;
					max=Integer.MIN_VALUE;
				}
			}
			//System.out.print(max);
			ans+=max==Integer.MIN_VALUE?a[n-1]:max;
			System.out.println(ans);
			
		}
		
		
		
		
		
		
		
		
		
		
		
		
	}
	static boolean sign(int a,int b) {
		return (a>0 && b>0) || (a<0 && b<0); 
	}
	
	
	
	static void print(int a[]) {
		for(int e:a) {
			System.out.print(e+" ");
		}
		System.out.println();
	}
	
	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; 
        } 
        int[] readArray(int n) {
    		int a[]=new int [n];
    		for(int i=0;i<n;i++) {
    			a[i]=sc.nextInt();
    		}
    		return a;
    	}
    } 
}






