
import java.util.Scanner;

public class KInversions {

	public static void main(String[] args) {
		
Scanner scn = new Scanner(System.in);
		
		int t = scn.nextInt();
		
		while(t-->0){
			int n = scn.nextInt();
			
			long arr[] = new long[n];
			
			for(int i=0;i<n;i++)
				arr[i] = scn.nextLong();
			
			long ans=0;		
			int i=0;
		      boolean pos = true;

		      if(arr[i]>0)
		        pos = true;
		      else
		        pos=false;
		      
		      while(i<n){

		          long inc = Integer.MIN_VALUE;
		          if(pos){
		              while(i<n&&arr[i]>0){
		                  inc = Math.max(inc,arr[i]);
		                  i++;
		              }
		              pos=!pos;
		              ans+=inc;
		          }
		          else{
		              while(i<n&&arr[i]<0){
		                  inc = Math.max(inc,arr[i]);
		                  i++;
		              }
		              pos=!pos;
		              ans+=inc;
		          }
		      }

		      System.out.println(ans);
		}
	}
	
	
}