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

public class Code1250F{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            System.out.println(substring(arr, n));
        }   
    }

    public static long substring(int[] a, int n){
       //ArrayList<Integer> al = new ArrayList<>();
       long sum = 0;
       int i = 0;
       while(i < a.length){
           int p = a[i];
           if(a[i] > 0){
               while(i < n && a[i] > 0){
                   if(a[i] > p)
                        p = a[i];
                    i++;
               }
           }
           else{
               while(i < n && a[i] < 0){
                   if(a[i] > p)
                        p = a[i];
                    i++;
               }
           }
           sum += p;
       }
       return sum;
    }
    /*
    public static void substring(int[] a, int n){
        //int[] dp = new int[a.length];
        int pvs = a[0];
        int sum = 0;
        for (int i = 1; i < n; i++){
            //positive
            if(a[i] > 0){
                //++
                if(a[i-1] > 0){
                    if(a[i] > pvs)
                        pvs = a[i];
                }
                //+-
                else{
                    sum += pvs;
                    pvs = a[i]; 
                }
            }
            //negative
            else{
                //-+
                if(a[i-1] > 0){
                    sum += pvs;
                    pvs = a[i];  
                }
                //--
                else{
                    if(a[i] > pvs)
                        pvs = a[i];
                    
                }
            }
        } 
    }
    */

    public static void printarr(int[] arr){
        for (int i = 0; i < arr.length ; i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }

    
    public static class FastScanner{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner(){ 
            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; 
        } 
    }
}