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

public class Problem {
   
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T-- > 0)
		{
		    int n = sc.nextInt();
		    long[] ar = new long[n];
		    for(int i=0;i<n;i++)ar[i]=sc.nextLong();
		    
		    long[][]  pre = new long[n][2];
		    if(ar[0] < 0)pre[0][0]=1;
		    else pre[0][1]=1;
		    long max=0;
		    for(int i=1;i<n;i++)
		    {
		        if(ar[i] < 0)
		        {
		            pre[i][0] = pre[i-1][1]+(long)1;
		            pre[i][1] = pre[i-1][1];
		        }
		        else 
		        {
		            pre[i][1] = pre[i-1][0]+(long)1;
		            pre[i][0] = pre[i-1][0];
		        }
		        
		        max = Math.max(max,Math.max(pre[i][0],pre[i][1]));
		    }
		    
		   
		    long sum=0,val=Long.MIN_VALUE;
		    int i=n-1;
		    while(max>0 && i>=0)
		    {
		        if(pre[i][0] == max || pre[i][1] == max)
		        {
		            val = Math.max(val,ar[i]);
		            i--;
		        }
		        else
		        {
		            sum+=val;
		            val=Integer.MIN_VALUE;
		            max--;
		        }
		    }
		    
		    sum += val;
		    
		    System.out.println(sum);
		    
		    
		    
		    
		    
		}
		
		
		
		
		
	}
}
