import java.io.*;
import java.util.*;
 
 
public class MyProgram{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      int n = sc.nextInt();
      
      for(int i = 0; i < n; i++){
          int inputs = sc.nextInt();
          int[] arr = new int[inputs];
          for(int j = 0; j < inputs; j++){
              arr[j] = sc.nextInt();
          }
          //solution
          int a = 0;
          int b = 0;
          int counter = 0;
          long maxSum = 0;
          if(arr[0] > 0){
              while(a+b < inputs){
                  if(counter % 2 == 0){
                      if(arr[a+b] < 0){
                          maxSum+=max(arr, a, a+b-1);
                          counter++;
                          a+=b;
                          b=0;
                      }
                      else{
                          b++;
                      }
                  }
                  
                  else{
                      if(arr[a+b] > 0){
                          maxSum += max(arr, a, a+b-1);
                          counter++;
                          a+=b;
                          b=1;
                      }
                      else{
                          b++;
                      }
                  }
                  
              }
              if(a+b == inputs){
                  maxSum += max(arr, a, a+b-1);
              }
          }
          else{
              while(a+b < inputs){
                  if(counter % 2 == 0){
                      if(arr[a+b] > 0){
                          maxSum += max(arr,a, a+b-1);
                          counter++;
                          a+=b;
                          b=0;
                      }
                      else{
                          b++;
                      }
                  }
                  
                  else{
                      if(arr[a+b] < 0){
                          maxSum += max(arr, a, a+b-1);
                          counter++;
                          a+=b;
                          b=0;
                      }
                      else{
                          b++;
                      }
                  }
              }
              if(a+b == inputs){
                  maxSum += max(arr, a, a+b-1);
              }
          }
          System.out.println(maxSum);
      }
      out.close();
   }
   
   public static int max(int[] arr, int start, int end){
       int max = Integer.MIN_VALUE;
       for(int i = start; i <= end; i++){
           max = Math.max(arr[i], max);
       }
       return max;
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
   //--------------------------------------------------------
}