// package Round_636;

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

public class Alt_Subsequence {  
    public static void main(String[] args) {
        FastReader in = new FastReader();
        
        int numTrials = in.nextInt();
        while(numTrials --> 0) {
            int lenArr = in.nextInt();
            int[] arr = new int[lenArr];
            
            for(int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            
            boolean lastPos = false;
            if(Integer.signum(arr[0]) == 1) {
                lastPos = true;
            }
            else {
                lastPos = false;
            }
            
            long sum = 0;
            int maxFromSection = arr[0];
            
            for(int i = 1; i < arr.length; i++) {
                int curr = arr[i];
                boolean isPos = (Integer.signum(curr) == 1);
                
                if(lastPos != isPos) {
                    sum += maxFromSection;
                    maxFromSection = Integer.MIN_VALUE;
                }
                
                maxFromSection = Math.max(curr, maxFromSection);
                lastPos = isPos;
            }
            
            sum += maxFromSection;
            System.out.println(sum);
        }
    }
    
    public static class SortLarge implements Comparator<Integer>{
        @Override
        public int compare(Integer arg0, Integer arg1) {
            return arg1.intValue() - arg0.intValue();
        }
    }
    
    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; 
        } 
    } 
}
