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
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t-- >0){
		    long sum=0;
		    int n=Integer.parseInt(br.readLine());
		    int a[]=new int[n];
		    String s[]=br.readLine().split(" ");
		    for(int i=0;i<n;i+=1){
	            a[i]=Integer.parseInt(s[i]);
                //System.out.print(a[i]+" ");
		    }
		    for(int i=0;i<n;){
		        int max=Integer.MIN_VALUE;
		        if(a[i]<0){
		            while(i<n && a[i]<0){
		                //System.out.println(a[i]);
		                if(a[i]>max){
		                    max=a[i];
		                    
		                }
		                i++;
		            }
		            sum+=max;
		            
		        }
		        else{
		            while(i<n && a[i]>0){
		                if(a[i]>max){
		                    max=a[i];
		                }
		                i++;
		            }
		            sum+=a[i-1];
		            //System.out.println(sum);
		        }
		    }
		    System.out.println(sum);
		}
	}
}