import java.util.Scanner;

public class Abhi {
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
	
		int t = s.nextInt();
		
		for(int k = 0; k<t; k++) {
			
			int n = s.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int m = 0;
			
		    for(int i = 0; i<n; i++) {
			    a[i] = s.nextInt();
		    }
		
		
		   for(int i = 0; i<n; i++) {
			   
			   if(a[i] > 0) {
	               int j = i;
	               int max = 0;
	               while(a[j] > 0) {
	        	       if(max < a[j]) {
	        		       max = a[j];
	        	       }
	        	       if(j == n-1) {
	        	    	   i = j;
	    	        	   break;
	        	       }
	        	    	   
	        	       j++;
	        	       i = j-1;
	                }
	                b[m] = max;
	                m++;
				
			     }
			   
			     if(a[i] < 0) {
			
				      int j = i;
				      int max1 = -1000000;
		              while(a[j] < 0) {
		        	   
		        	       if(max1 < a[j]) {
		        		   
		        		       max1 = a[j];
		    
		        	       }
		        	   
		        	       if(j == n-1) {
		        	    	   i = j;
		    	        	   break;
		        	       }
		        	      
		        	      j++;
		        	      i = j-1;
		              }
		          
		              b[m] = max1;
		              m++;
			      }
			
		      }
		   int sum = 0;
		   for(int i = 0; i<n; i++) {

			    
				if(b[i] == 0) {
					break;
				}
				else {
					sum += b[i];
				}	
			}
		   System.out.println(sum);
	    }
	
	}	
} 