/* 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		
		int t=sc.nextInt();
		for(int x1=0;x1<t;x1++){
		    int n=sc.nextInt();
		    int a[]=new int[n];
		    for(int i=0;i<n;i++){
		        a[i]=sc.nextInt();
		    }
		    if(n==1){
		        System.out.println(a[0]);
		    }
		    else{
		    int max=a[0];
		    long sum=0;
		    for(int i=0;i<n-1;i++){
		        if((a[i]>0 && a[i+1]<0)||(a[i]<0 && a[i+1]>0) ){
		            max=Math.max(max,a[i]);
		            sum=sum+max;
		          max=a[i+1];
		        }
		        else{
		            max=Math.max(max,a[i]);

		        }
		    }
		  
		    
		        sum=sum+max;
		    
		System.out.println(sum);
		    }
		    
		}
	}
}