import java.util.*;
import java.io.*;
 
 
 public class gfg  {
 
    static PrintWriter out = new PrintWriter(System.out);
    
    public static void main(String[] args) throws IOException{
        Reader.init(System.in);
        int t = Reader.nextInt();
        while(t-->0){
            solve();
        }
        out.close();
    }
   // static int n =0,m=0;
    static long mod =1000000007;
    static int MOD = 1000000007;
    static int[] dx = {0,0,1,-1};
    static int[] dy = {1,-1,0,0};
    //static int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
    static ArrayList<Integer>[] graph; 
    static int n=0,m=0;
    static int first=0,dist=0,max=0;
    static long[] arr;
    //static HashSet<Integer> set = new HashSet<>();
    static HashMap<Integer,Integer> map = new HashMap<>();
    static Long[][] dp;
    static void solve() throws IOException{
        n = Reader.nextInt();
        arr  = new long[n];
        dp = new Long[n+5][2];
        for(int i=0;i<n;i++){
            long x = Reader.nextLong();
            arr[i] = x;
        }
        if(arr[0]>0)
            System.out.println(solve(0,1));
        else
            System.out.println(solve(0,0));
    }

    static long solve(int ind, int sign){
        if(ind>=n)
            return 0;
        long x = arr[ind];
        long ans = -1000000000;
        if(dp[ind][sign]!=null)
            return dp[ind][sign];
        if(sign==0){//pos{
            if(x<0)
                ans = arr[ind] + solve(ind+1,1);
            if(x<0 && ind<n-1 && arr[ind+1]<0)
                ans = Math.max(ans,solve(ind+1,0));
            if(x>0)
                ans = solve(ind+1,0);
        }
        else{
            if(x>0)
                ans = arr[ind] + solve(ind+1,0);
            if(x>0 && ind<n-1 && arr[ind+1]>0)
                ans = Math.max(ans,solve(ind+1,1));
            if(x<0)
                ans = solve(ind+1,1);
        }
        return dp[ind][sign] = ans;
    }
    
 
    


    // ggratest common divisor println
    static int gcd(int a , int b){
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }
 
    // least common multiple
    static int lcm(int a, int b){
        return (a*b)/gcd(a,b);
    }
    
    // a^b
    static long fastpow(long a, long b){
        long res = 1;a=a%mod;
        while(b>0){
            if(b%2==1)
                res = (res*a)%mod;
            a = (a*a)%mod;
            b = b>>1;
        }
        return res;
    }
 
 
    
 
 
    // SEGMENT TREE
    // static void update(int cur,int val, int ind, int l, int h){
    //     if(l==h){
    //         seg[cur] = val;
    //         return;
    //     }
    //     int mid = (l+h)/2;
    //     if(ind<=mid){
    //         update(2*cur+1,val,ind,l,mid);
    //     }
    //     else{
    //         update(2*cur+2,val,ind,mid+1,h);
    //     }
    //     seg[cur] = seg[2*cur+1] + seg[2*cur+2];
    // }
    
    // static int query(int cur, int l, int h , int reql, int reqh){
    //     if(reql>reqh || l>h)
    //         return 0;
    //     if(l==reql && h==reqh)
    //         return seg[cur];
    //     int mid = (l+h)/2;
    //     return query(2*cur+1,l,mid,reql,Math.min(reqh,mid)) + query(2*cur+2,mid+1,h,Math.max(mid+1,reql),reqh);
    //}
 
    // priority queue with comparator
    // PriorityQueue<Interval> pq = new PriorityQueue<>(new Comparator<Interval>() {
    //             public int compare(Interval a, Interval b){
    //                 int diff1 = a.r - a.l;
    //                 int diff2 = b.r - b.l;
 
    //                 if(diff1 == diff2){
    //                     return a.l - b.l;
    //                 }
 
    //                 return diff2 - diff1;
    //             }
    // });
}
 
class trienode{
        int v;
        trienode[] child ;
        boolean leaf;
        int cnt;
        int p=0;
        trienode(int vv){
            child = new trienode[2];
            leaf=false;
            cnt=0;
            v=vv;
        }
        trienode(){
            child = new trienode[2];
            leaf=false;
            cnt=0;
            v=0;
        }
    }
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 newcomparator implements Comparator<Integer>{
    //@Override
    public int compare(Integer a, Integer  b){
        return a<=b?1:-1;
    }
 }
class node {
    int f;
    int s;// cost to rreach\
    node(int ff,int ss){
        f=ff;
        s=ss;
    }
}
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++;
        }
    }
    
}
