import java.util.*;
import java.io.*;
 
/** Class for buffered reading int and double values */
 
 public class gfg {
    
    static ArrayList<Integer>[] graph;
    static boolean[] vis;
    static int verts=0;
    static long edges=0;
    //static int flag=0;

    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        Reader.init(System.in);
        int t = r.nextInt();
        while(t-->0){
            int n = r.nextInt();
            long[] arr = new long[n];
            long sum =0;
            
            for(int i=0;i<n;i++){
                arr[i] = r.nextLong();
            }
            long max=Long.MIN_VALUE;
            for(int i=0;i<n-1;i++){

                //int max = Integer.MIN_VALUE;
                max=arr[i];
                while(i<n-1 && arr[i]*arr[i+1]>0 ){  //same sign continues.
                    max = Math.max(max,arr[i]);
                    i++;
                }
                if(i<n-1 &&  arr[i]*arr[i+1]<0 ){
                    max = Math.max(max,arr[i]);
                }

                sum+=max;
                //System.out.println(i+" "+sum);
                

            }
            if(n>1 && arr[n-1]*arr[n-2]<0 )
                sum+=arr[n-1];
            System.out.println(sum);
        }
        
    } 


    static void solve(){

    }

    static void dfs(int i){
        vis[i]=true;
        verts++;
        edges+=graph[i].size();
        for(int j=0;j!=graph[i].size();j++){
            int x = graph[i].get(j);
            if(!vis[x]){
                dfs(x);
            }
        }
    }


    static long fastpow(long a, long n){
        //System.out.println("ssdf");
        if(n>0){
            long half = fastpow(a,n/2);
            if(n%2==0){
                return half*half;
            }
            else
                return a*half*half;
        }
        return 1;
    }

    
}


class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

class node {
    int a;
    int b;// cost to rreach\
    int dif =0;
    node(int v,int va){
        a=v;
        b=va;
        dif = Math.abs(b) - Math.abs(a);
    }
}
class mergesort{
    static void sort(int l, int h, int[] arr){
        if(l<h){
            int mid = (l+h)/2;
            
            sort(l,mid,arr);
            sort(mid+1,h,arr);
            merge(l,mid,h,arr);
        }
    }
    static void merge(int l, int m , int h , int [] arr){

        int[] left = new int[m-l+1];
        int[] right = new int[h-m];
        for(int i= 0 ;i< m-l+1;i++){
            left[i] = arr[l+i];
        }
        for(int i=0;i<h-m;i++){
            right[i] = arr[m+1+i];
        }
        //now left and right arrays are assumed to be sorted and we have tp merge them together 
        // int the original aaray.
        int i=l;
        int lindex = 0;
        int rindex =  0;
        
        while(lindex<m-l+1 && rindex<h-m){
            if(left[lindex]<=right[rindex]){
                arr[i]=left[lindex];
                lindex++;
                i++;
            }
            else{
                arr[i]=right[rindex];
                rindex++;
                i++;
            }
        }
        while(lindex<m-l+1){
            arr[i]=left[lindex];
            lindex++;
            i++;
        }
        while(rindex<h-m){
            arr[i]=right[rindex];
            rindex++;
            i++;
        }
    }
    
}








