import java.util.*;
public class Main {
    public static void main(String args[]) {
       Scanner sc = new Scanner(System.in);
       int t = sc.nextInt();
       while(t-- > 0){
           int n = sc.nextInt();
           int[] arr = new int[n];
           for(int k = 0; k < n; k++){
               arr[k] = sc.nextInt();
           }
           //Check for all Positive Array
           boolean allPositive = true;
           int maxP = Integer.MIN_VALUE;
           for(int i = 0; i < n; i++){
               if(arr[i] <= 0){
                   allPositive = false;
               }
               if(maxP < arr[i]){
                   maxP = arr[i];
               }

           }
           if(allPositive){
               System.out.println(maxP);
               break;
           }

           //Check for all Negative Array
           boolean allNegative = true;
           int maxN = Integer.MIN_VALUE;
           for(int j = 0; j < n; j++){
               if(arr[j] >= 0){
                   allNegative = false;
               }
               if(maxN < arr[j]){
                   maxN = arr[j];
               }

           }
           if(allNegative){
               System.out.println(maxN);
               break;
           }

           // Type Positive-Negative
           
           if(arr[0] > 0){
               int sum = 0;
               
               int i = 0;
               while(i < n){
              int max = Integer.MIN_VALUE;
               while((i < n) && (arr[i] > 0)){
                   if(max < arr[i]){
                       max = arr[i];
                       
                   }
                   i++;
               }
               sum += max;

               int maxNe = Integer.MIN_VALUE;
               while((i < n) && (arr[i] < 0)){
                   if(maxNe < arr[i]){
                       maxNe = arr[i];
                      
                   }
                   i++;
               }
               sum += maxNe;
               }
              System.out.println(sum);
              break;

           }


           //Type Negative-Positive
           if(arr[0] < 0){
               int sum = 0;
              
               int i = 0;
               while(i < n){
                int max = Integer.MIN_VALUE;
               while((i < n) && (arr[i] < 0)){
                   if(max < arr[i]){
                       max = arr[i];
                       
                   }
                   i++;
               }
               sum += max;

               int maxNe = Integer.MIN_VALUE;
               while((i < n) && (arr[i] > 0)){
                   if(maxNe < arr[i]){
                       maxNe = arr[i];
                      
                   }
                   i++;
               }
               sum += maxNe;
               }
              System.out.println(sum);
              break;

           }

       }
    }
}