import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.Iterator; 
import java.util.TreeSet;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;


public class C1343{
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	static FastReader sc = new FastReader();
	static boolean[] sieve = new boolean[10000001];
	public static void main(String[] args) {
		int t = sc.nextInt();
		//Arrays.fill(sieve, true);
        //soe();
		while(t-->0){
		    int n = sc.nextInt();
		    int[] a = new int[n];
		    long ans = 0;
		    int max = Integer.MIN_VALUE;
		    for(int i = 0; i < n; i++){
		        a[i] = sc.nextInt();
		    }
		    for(int i = 0; i < n; i++){
		        max = Math.max(max,a[i]);
		        if(i==n-1){
		            out.print(max+" ");
		            ans += max;
		        }
		        else if(a[i]*a[i+1]<0){
		            out.print(max+" ");
		            ans += max;
		            max = Integer.MIN_VALUE;
		        }
		    }
		    out.println(ans);
		}
		out.close();
	}
	//static void soe() {
	//	sieve[0]=sieve[1]=false;
	//	for(int i=2;i<=10000000;i++) {
	//		if(sieve[i]) {
	//			if(i*1l*i<=10000000) {
	//				for(int j = i*i;j<=10000000;j+=i) {
	//					sieve[j] = false;
	//				}
	//			}
	//		}
	//	}
	//}
	public static int ffloor(int[] b, long ele){
	    int s = 0;
	    int e = b.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(b[m] == ele){
	            return b[m];
	        }
	        else if(b[m]>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return b[e];
	}
	public static int cceil(int[] a, long ele){
	    int s = 0;
	    int e = a.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(a[m] == ele){
	            return a[m];
	        }
	        else if(a[m]>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return a[s];
	}
	public static int floor(ArrayList<Pair> A , long ele){
	    int s = 0;
	    int e = A.size()-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(A.get(m).x == ele){
	            return A.get(m).x;
	        }
	        else if(A.get(m).x>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return A.get(e).x;
	}
	public static int ceil(Pair[] a, long ele){
	    int s = 0;
	    int e = a.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(a[m].x == ele){
	            a[m].y = 1;
	            return a[m].x;
	        }
	        else if(a[m].x>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    a[s].y = 1;
	    return a[s].x;
	}
	////////////////////////////////////////////////////////////////////////////////
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if(this.x==o.x){
			    return (this.y-o.y);
			}
			return (this.x-o.x);
		}
	}
	public static boolean isPrime(int n){
	    if(n < 2){
	        return false;
	    }
	    if(n%2==0){
	        return n==2;
	    }
	    if(n%3==0){
	        return n==3;
	    }
	    int i = 5;
	    int h = (int)Math.floor(Math.sqrt(n)+1);
	    while(i <= h){
	        if(n%i==0){
	            return false;
	        }
	        if(n%(i+2)==0){
	            return false;
	        }
	        i += 6;
	    }
	    return true;
	}
	public static long gcd(long a, long b){
	    return b==0? a:gcd(b, a%b);
	}
	public static long bSearch(int n,ArrayList<Long> A){
	    int s = 0;
	    int e = A.size()-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(A.get(m)==(long)n){
	            return A.get(m);
	        }
	        else if(A.get(m)>(long)n){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return A.get(s);
	}
	static long modulo = (long)1e9+7;
	public static long modinv(long x){
	    return modpow(x, modulo-2);
	}
	public static long modpow(long a, long b){
	    if(b==0){
	        return 1;
	    }
	    long x = modpow(a, b/2);
	    x = (x*x)%modulo;
	    if(b%2==1){
	        return (x*a)%modulo;
	    }
	    return x;
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}