/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException
    {
       // System.out.println("enter the number of test cases");
        int t = 0;
        FastReader sc = new FastReader();
        BufferedWriter w=new BufferedWriter(new PrintWriter(System.out));
        t = sc.nextInt();
        for (int i = 0; i < t; i++)
        {
           // System.out.println("enter the value of n");
            int n = sc.nextInt();
            long a[]=new long [n];
            int pos=0;
            int neg=0;
            int total=0;
            int sign=0;
            //System.out.println("Enter the array");
            long max=Long.MIN_VALUE;
            long sum=0;
            for(int x=0;x<n;x++)
            {
                a[x]=sc.nextInt();
                if(x==0)
                {
                    max=a[0];
                    if(a[x]>0)
                    {
                        sign=1;
                        pos++;
                        total++;
                    }
                    else
                    {
                        sign=-1;
                        neg++;
                        total++;
                    }
                }
               else if(a[x]>0&&sign<0)
                {
                    pos++;
                    total++;
                    sum+=max;
                    max=a[x];
                    if(x==n-1)
                    {
                        sum+=max;
                    }
                    sign=1;
                }
                else if(a[x]<0&&sign>0)
                {
                    neg++;
                    total++;
                    sum+=max;
                    max=a[x];
                    if(x==n-1)
                    {
                        sum+=max;
                    }
                    sign=-1;
                }
                else
                {
                    if(a[x]>max)
                    {
                        max=a[x];
                    }
                    if(x==n-1)
                    {
                        sum+=max;
                    }
                }
            }
           // System.out.println(total);
            w.write(Long.toString(sum)+"\n");
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}
