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

 
public class Main
{
   // static LinkedList<Integer> adj[];
    /*static void BFS(int s,boolean visited[]){
        visited[s]=true;
        Queue<Integer> queue=new LinkedList<>();
        while(queue.size()!=0){
            int n=queue.poll();
            visited[n]=true;
            Iterator<Integer> itr=adj[n].listIterator();
            while(itr.hasNext()){
                int q=itr.next();
                if(!visited[q]){
                    queue.add(q);
                }
            }
        }
    }*/
    /*static void DFS(int s,boolean visited[]){
        visited[s]=true;
        Iterator<Integer> itr=adj[s].listIterator();
        while(itr.hasNext()){
            int n=itr.next();
            if(visited[n]!=true){
                DFS(n,visited);
            }
        }
    }*/
    public static void main(String[] args)
    {
        FastReader s=new FastReader();
		 int t=s.nextInt();
	   for(int f=0;f<t;f++)
        {
            int n=s.nextInt();
            long a[]=new long[n];
            for(int i=0;i<n;i++){
                a[i]=s.nextLong();
            }
            int maxsize=0;
            long maxsum=0;
            maxsum=a[0];maxsize=1;
            int c=-1,d=-1;
            if(a[0]<0)
            d=0;
            else c=0;
            for(int i=1;i<n;i++){
                if(a[i]>0 && a[i-1]>0){
                    if(a[i]>a[c]){
                        maxsum=maxsum-a[c]+a[i];
                        c=i;
                    }
                }
                else if(a[i]>0){
                    maxsize++;
                    maxsum=maxsum+a[i];
                    c=i;
                }
                else if(a[i]<0 && a[i-1]<0){
                    if(a[i]>a[d]){
                        maxsum=maxsum-a[d]+a[i];
                        d=i;
                    }
                }
                else{
                    maxsize++;
                    maxsum=maxsum+a[i];
                    d=i;
                }
            }
            // System.out.println(maxsize);
            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;
        }
    }
 
   
}
        