import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;


import java.util.*;


public class Main {


    Set<Integer>set=new HashSet<>();
    public boolean canVisitAllRooms(List<List<Integer>> rooms) {

        List<Integer>s=new ArrayList<>(rooms.get(0));
        for (int i = 0; i < s.size(); i++) {
            set.add(s.get(i));
        }
        for (int i = 0; i < s.size(); i++) {
            for(int it:rooms.get(i)){
                if (!set.contains(it)){
                    s.add(it);
                    set.add(it);
                }
            }
        }

        return rooms.size()==set.size();


    }



    public static void main (String[]args) throws IOException {
        Scanner in = new Scanner(System.in);


        try (PrintWriter or = new PrintWriter(System.out)) {

            int t=in.nextInt();

            outer:
            while (t-->0){
                int n=in.nextInt();
                int less=0,big=0;
                long[]a=new long[n];
                for (int i = 0; i < n; i++) {
                    a[i]=in.nextLong();
                    if (a[i]<0)less++;
                    else if (a[i]>0)big++;
                }
                if (less>0){
                    long sss=Integer.MIN_VALUE;
                    if (big==0){
                        for (int i = 0; i < n; i++) {
                            sss=Math.max(sss,a[i]);
                        }
                        or.println(sss);
                        continue outer;
                    }
                }

                if (big>0){
                    long sss=0;
                    if (less==0){
                        for (int i = 0; i < n; i++) {
                            sss=Math.max(sss,a[i]);
                        }
                        or.println(sss);
                        continue outer;
                    }

                }
                
                if (a[0]>0){
                    long max=0;
                    int i=0;
                    long sum1=0;
                    int num1=0;
                    while (i<n) {
                        max=0;
                        long max2=Integer.MIN_VALUE;
                        boolean found=false;
                        for (; i < n; i++) {
                            if (a[i] > 0) {
                                max = Math.max(a[i], max);
                                found=true;
                            }
                            else {
                                if (found)break;
                            }
                        }
                        if (!found)break;
                        sum1+=max;
                        found=false;
                        for(;i<n;++i){
                            if (a[i]<0){
                                max2=Math.max(a[i],max2);
                                found=true;
                            }
                            else {
                                if (found)break ;
                            }
                        }
                        if (!found)break;


                        sum1+=max2;
                    }
                    or.println(sum1);


                }else{

                    long max3=0;
                    int i=0;

                    long sum2=0;
                    int nuum2=0;
                    while (i<n) {
                        max3=Integer.MIN_VALUE;
                        boolean found=false;
                        long max4=0;
                        for (; i < n; i++) {
                            if (a[i] < 0) {
                                max3 = Math.max(a[i], max3);
                                found=true;
                            }
                            else {
                                if (found)break ;
                            }
                        }
                        if (!found)break ;
                        sum2+=max3;
                        found=false;
                        for(;i<n;++i){
                            if (a[i]>0){
                                max4=Math.max(a[i],max4);
                                found=true;
                            }
                            else{
                                if (found) break ;
                            }
                        }
                        if (!found)break ;



                        sum2+=max4;
                    }
                    or.println(sum2);
                }






            }








        }
    }




    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static int getlen(int r,int l,int a){
        return (r-l+1+1)/(a+1);
    }






    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Pair implements Comparable<Pair> {
    int first, second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }


    @Override
    public int compareTo(Pair o) {
        if (first!=o.first)return first-o.first;
        return second-o.second;
    }
}

class Tempo {

    int first,second,third;

    public Tempo(int first, int second, int third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }
}