
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class C {
    public static void main(String[] args)
    {
        FastReader s = new FastReader();
        int t = s.nextInt();
        while(t-->0)
        {
            int n = s.nextInt();
            int[] a = s.nextIntArr();

            int k=1;
            boolean positive = a[0]>0;

            long maxSum=0;
            int maxElement=a[0];

            for (int i = 1; i < n; i++) {
                if(a[i]>0)
                {
                    if(!positive)
                    {
                        k++;
                        positive = !positive;
                        maxSum+=maxElement;
                        maxElement=a[i];
                    }
                    else
                    {
                        if(a[i]>maxElement) maxElement=a[i];
                    }
                }
                else
                {
                    if(positive)
                    {
                        k++;
                        positive=!positive;
                        maxSum+=maxElement;
                        maxElement=a[i];
                    }
                    else
                    {
                        if(a[i]>maxElement) maxElement=a[i];
                    }
                }
            }
            maxSum+=maxElement;
            System.out.println(maxSum);
        }
    }
    


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

        int[] nextIntArr() {
            String[] str = nextLine().split(" ");
            int[] arr = new int[str.length];
            try
            {
                for (int i = 0; i < arr.length; i++) {
                    arr[i] = Integer.parseInt(str[i]);
                }
            }
            catch (NumberFormatException e)
            {
                e.printStackTrace();
            }
            return arr;
        }
    }
}
