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


public class C {

    public static void main(String[] args) throws IOException {
        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        int testCase = Integer.parseInt(inp.readLine());
        while (testCase-->0){


            int size = Integer.parseInt(inp.readLine());
            long[] given = new long[size];
            String[] s1 = inp.readLine().split(" ");
            int count  =1;
            for(int i=0;i<size;i++){
                given[i] = Integer.parseInt(s1[i]);
                if(i>=1){
                    if(given[i]*given[i-1]<0){
                        count++;
                    }
                }
            }

            //System.out.println(count);
            ArrayList<Long> list = new ArrayList<>();
            list.add(given[0]);
            long sum = 0;

            boolean pos = false;

            for(int i=1;i<size;i++){

                if(list.get(list.size()-1)*given[i]>0){
                    if(given[i]>list.get(list.size()-1)){
                        list.set(list.size()-1,given[i]);
                    }
                }
                else{
                    list.add(given[i]);
                }

            }

            for(int i=0;i<list.size();i++){
                sum+=list.get(i);
            }
            out.write(sum+"\n");





        }
        out.flush();


    }
    static long[] decToBinary(long n,long k)
    {
        // array to store binary number
        long[] binaryNum = new long[64];

        // counter for binary array
        int i = 0;
        while (n > 0L) {
            // storing remainder in binary array
            binaryNum[i] = n % k;
            n = n / k;
            i++;
        }
        return binaryNum;
    }
    static void print(int[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(int[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(boolean[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(boolean[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(long[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(long[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(String[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(String[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static long calc(int a,int b){
        long c = b-a+1;
        c = c*(c+1);
        c/=2l;
        return c;
    }
}

