   // Jai mata di
import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.nio.file.attribute.FileAttribute;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;



public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            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;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int t =sc.nextInt();
        for(int i=0;i<t;i++){
            int n=sc.nextInt();
           int[] arr=new int[n];
           for(int j=0;j<n;j++){
               arr[j]=sc.nextInt();
           }
           TreeSet<Integer> set=new TreeSet<>();
           int flag=0;
           if(arr[0]>0){
               flag=1;
           }
           else{
               flag=0;
            }
           set.add(arr[0]);
           long sum=0;
           for(int j=1;j<n;j++){
               if(arr[j]>0){
                   if(flag==1){
                       set.add(arr[j]);
                   }
                   else{
                       sum+=set.last();
                       set.clear();
                       flag=1;
                       set.add(arr[j]);
                   }
                   if(j==n-1){
                       sum+=set.last();
                   }
               }
               else{
                   if(flag==0){
                       set.add(arr[j]);
                   }
                   else{
                       sum+=set.last();
                       set.clear();
                       flag=0;
                       set.add(arr[j]);
                   }
                   if(j==n-1){
                       sum+=set.last();
                   }
               }
           }
           System.out.println(sum);

        }

    }
}


