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

public class C
{
    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;
            }
    }

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    
    public static void main(String[] args) 
    {
        int t = 1;
        t = sc.nextInt();
        while(t-- > 0)
        {
            int n = sc.nextInt();
            long arr[] = new long[n];
            int i;
            for(i=0;i<n;i++)
                arr[i] = sc.nextLong();

            long min=0,max=0;
            long flg;            
            long ans = 0;
            i=0;
            if(n==1)
            {
                out.println(arr[0]);
            }
            else
            {
                if(arr[0]>0)
                {
                    flg=1;
                    max = arr[0];
                    if(arr[i+1]<0 && (i+1)!=n)
                    {
                        min = arr[i+1];
                        flg=0;
                        ans = ans+max;
                    }
                }
                else
                {
                    flg=0;
                    min = arr[0];
                    if(arr[i+1]>0 && (i+1)!=n)
                    {
                        flg=1;
                        max = arr[i+1];
                        ans = ans + min;
                    }
                }

                for(i=1;i<n;i++)
                {
                    //out.println("### "+min);

                    if(i==n-1)
                    {
                        if(flg==1)
                            ans = ans+max;
                        else
                            ans = ans+min;
                    }
                    else
                    {
                        //out.println("******* "+i);
                        if(flg==1)
                        {
                            if(arr[i]>0)
                                max = Math.max(arr[i],max);
                            if(arr[i+1]<0)
                            {
                                min = arr[i+1];
                                flg=0;
                                ans = ans+max;
                            }
                        }
                        else
                        {
                            if(arr[i]<0)
                                min = Math.max(arr[i],min);
                            if(arr[i+1]>0)
                            {
                                flg=1;
                                max = arr[i+1];
                                ans = ans + min;
                            }
                        }
                    }
                }
                out.println(ans);
            }
            out.flush();

        }    
    }
}