import java.util.*;
//import java.io.*;
public class SubsequenceAlternating
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int T;
        T=in.nextInt();
        while((T--)>0)
        {
            //code comes here
            long pospointer=-1,negpointer=-1,lenpos=0,lenneg=0,sumPos=0,sumNeg=0;
            int N=in.nextInt();
            long arr[]=new long[N];
            for(int i=0;i<N;i++)
            {
                arr[i]=in.nextLong();
                if(arr[i]>=0)
                {
                    if(negpointer==-1)
                    {
                        if(pospointer==-1)
                        {
                            pospointer=i;
                            lenpos=1;
                            sumPos=arr[i];
                        }
                        else
                        {
                            if(arr[i]>sumPos)
                            {
                                pospointer=i;
                                lenpos=1;
                                sumPos=arr[i];
                            }
                        }
                    }
                    else
                    {
                        if(pospointer==-1)
                        {
                            pospointer=i;
                            sumPos=sumNeg+arr[i];
                            lenpos=lenneg+1;
                        }
                        else
                        {
                            if(lenpos<(lenneg+1))
                            {
                                pospointer=i;
                                sumPos=sumNeg+arr[i];
                                lenpos=lenneg+1;
                            }
                            else
                            {
                                if(sumPos<(sumNeg+arr[i]))
                                {
                                    pospointer=i;
                                    sumPos=sumNeg+arr[i];
                                    lenpos=lenneg+1;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if(pospointer==-1)
                    {
                        if(negpointer==-1)
                        {
                            negpointer=i;
                            sumNeg=arr[i];
                            lenneg=1;
                        }
                        else
                        {
                            if(arr[i]>sumNeg)
                            {
                                negpointer=i;
                                sumNeg=arr[i];
                                lenneg=1;
                            }
                        }
                    }
                    else
                    {
                        if(negpointer==-1)
                        {
                            negpointer=i;
                            sumNeg=arr[i]+sumPos;
                            lenneg=1+lenpos;
                        }
                        else
                        {
                            if(lenneg<(lenpos+1))
                            {
                                negpointer=i;
                                sumNeg=sumPos+arr[i];
                                lenneg=lenpos+1;
                            }
                            else
                            {
                                if(sumNeg<(sumPos+arr[i]))
                                {
                                    negpointer=i;
                                    sumNeg=sumPos+arr[i];
                                    lenneg=lenneg+1;
                                }

                            }
                        }

                    }

                }
                //System.out.println("negPointer is "+negpointer+" posPointer is "+pospointer+" sumpos is "+sumPos+" sumneg is "+sumNeg);

            }

            if(lenpos>lenneg)
            {
                System.out.println(sumPos);
            }
            else
            {
                System.out.println(sumNeg);
            }

        }   
        in.close();
    }

}