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

public class C636 {

    public static void solve(InputReader in, PrintWriter out) throws Exception {

        int t= in.nextInt();
        while(t--!=0)
        {
            int n = in.nextInt();
            int[] arr = new int[n];

            for(int i=0;i<n;i++)
                arr[i]=in.nextInt();

            int[] dp = new int[n];
            dp[0]=1;

            for(int i=1;i<n;i++)
            {
                int elm = arr[i];
                int j = i-1;
                while(j>=0 && elm*arr[j]>0)
                {
                    j--;
                }

                if(j==-1)
                    dp[i]=1;
                else
                    dp[i]=dp[j]+1;

            }

            long ans = 0;
            for(int i=0;i<n;)
            {
                int max = arr[i];
                i++;
                while(i<n && dp[i]==dp[i-1])
                {
                    max=Math.max(max,arr[i]);
                    i++;
                }

                ans = ans +max;
            }



            out.println(ans);

        }


    }


    /////////////////////////////////////////////////////////


    private final static long hash(long x, long y) {
        x += offset;
        y += offset;
        return x << 32 | y;
    }

    private final static int offset = (int) 3e5;

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        private String nextToken()throws IOException{
            while(tokenizer==null || !tokenizer.hasMoreTokens())
                tokenizer=new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }
        public String nextLine()throws IOException{
            return reader.readLine();
        }
        public int nextInt()throws IOException{
            return Integer.parseInt(nextToken());
        }
        public long nextLong()throws IOException{
            return Long.parseLong(nextToken());
        }
        public double nextDouble()throws IOException{
            return Double.parseDouble(nextToken());
        }

    }
}
