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

   public class C
   {
      public static void main(String kurome[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         while(T-->0)
         {
            int N = Integer.parseInt(infile.readLine());
            int[] arr = new int[N];
            st = new StringTokenizer(infile.readLine());
            for(int i=0; i < N; i++)
               arr[i] = Integer.parseInt(st.nextToken());
            int tag = 0;
            if(arr[0] < 0)
               tag = 1;
            int max = arr[0];
            long res = 0L;
            for(int i=1; i < N; i++)
            {
               if(tag == 0)
               {
                  if(arr[i] > 0)
                     max = Math.max(max, arr[i]);
                  else
                  {
                     res += max;
                     tag = 1;
                     max = arr[i];
                  }
               }
               else
               {
                  if(arr[i] < 0)
                     max = Math.max(max, arr[i]);
                  else
                  {
                     res += max;
                     tag = 0;
                     max = arr[i];
                  }
               }
            }
            res += max;
            sb.append(res+"\n");
         }
         System.out.print(sb);
      }
   }