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

public class Solution {

    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        int i=0,j=0,k=0;
        for (int testcase=0;testcase<t;testcase++)
        {
            long n=sc.nextInt();
            long arr[]=new long[(int) n];
            for (i=0;i<n;i++)
            {
                arr[i]=sc.nextInt();
            }
            i=0;
            long temp=arr[0];
            long sum=0;
            while (i<n)
            {
                if (temp<0)
                {

                    long max=Integer.MIN_VALUE;
                    while (temp<0 && i<arr.length)
                    {
                        if (max<temp)
                        {
                            max=temp;
                        }
                        i++;
                        if (i<arr.length)
                        temp=arr[i];
                    }
                    sum+=max;
                    System.out.println(max);
                    System.out.println(sum);
                }
                else
                {
                    long max=Integer.MIN_VALUE;
                    while (temp>0 && i<arr.length)
                    {

                        if (max<temp)
                        {
                            max=temp;
                        }
                        i++;
                        if (i<arr.length)
                        temp=arr[i];
                    }
                    System.out.println(max);
                    sum+=max;
                    System.out.println(sum);
                }
            }

            System.out.println(sum);

        }
    }

    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;
        }
    }
}
