import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(br.readLine());
            long arr[]=new long[n];
            String line=br.readLine();
            String str[]=line.trim().split("\\s+");
            for(int i=0;i<n;i++)
            {
                arr[i]=Integer.parseInt(str[i]);
            }
            int sign=1;
            long sum=0,prev=arr[0];
            if(arr[0]<0)
            sign=0;
            
            for(int i=1;i<n;i++)
            {
                if(arr[i]>0)
                {
                    if(sign==0)
                    {
                        //System.out.println(prev);
                        sum+=prev;
                        prev=arr[i];
                        sign=1;
                    }
                    else
                    {
                         if(prev<arr[i])
                         prev=arr[i];
                     
                    }
                    if(i==n-1){
                         //System.out.println(prev);
                            sum+=prev; }  
                     
                }
                else
                {
                    if(sign==1)
                    {
                        //System.out.println(prev);
                        sum+=prev;
                        prev=arr[i];
                        sign=0;
                    }
                    else
                    {
                        if(prev<arr[i])
                        {
                            prev=arr[i];
                            
                        }
                        
                    }
                    if(i==n-1){
                        //System.out.println(prev);
                            sum+=prev;}
                }
            }
            System.out.println(sum);
        }
    }
}