import java.io.*;
import java.util.*;



public class Main
{

   public static void main(String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      int T = Integer.parseInt(input.readLine());
      for(int t = 0; t < T; t++)
      {
         int N = Integer.parseInt(input.readLine());
         long[] arr = new long[N];
         StringTokenizer st = new StringTokenizer(input.readLine());
         for(int i = 0; i < N; i++)
         {
            arr[i] = Long.parseLong(st.nextToken());
         }
         int[] lastPosBefore = new int[N];
         int[] lastNegBefore = new int[N];
         lastPosBefore[0] = -1;
         lastNegBefore[0] = -1;
         for(int i = 1; i < N; i++)
         {
            if(arr[i - 1] > 0) lastPosBefore[i] = i - 1;
            else lastPosBefore[i] = lastPosBefore[i - 1];
            if(arr[i - 1] < 0) lastNegBefore[i] = i - 1;
            else lastNegBefore[i] = lastNegBefore[i - 1];
         }
         int[] size = new int[N];
         long[] sum = new long[N];
         size[0] = 1;
         sum[0] = arr[0];
         for(int i = 1; i < N; i++)
         {
            if(arr[i] > 0)
            {
               if(lastNegBefore[i] == -1)
               {
                  size[i] = 1;
                  sum[i] = arr[i];
               }
               else
               {
                  size[i] = size[lastNegBefore[i]] + 1;
                  sum[i] = sum[lastNegBefore[i]] + arr[i];
               }
               if(size[i - 1] > size[i] || size[i - 1] == size[i] && sum[i - 1] > sum[i])
               {
                  size[i] = size[i - 1];
                  sum[i] = sum[i - 1];
               }
            }
            else
            {
               if(lastPosBefore[i] == -1)
               {
                  size[i] = 1;
                  sum[i] = arr[i];
               }
               else
               {
                  size[i] = size[lastPosBefore[i]] + 1;
                  sum[i] = sum[lastPosBefore[i]] + arr[i];
               }
               if(size[i - 1] > size[i] || size[i - 1] == size[i] && sum[i - 1] > sum[i])
               {
                  size[i] = size[i - 1];
                  sum[i] = sum[i - 1];
               }
            }
         }
         System.out.println(sum[N - 1]);
      }
   }

}