import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sri Mouli (sri.vcmk@gmail.com)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);
            long sum = 0;
            int currentObj = a[0];
            int curIndex = 0;
            for (int i = 1; i < n; i++) {
                if ((a[i] ^ currentObj) < 0) {
                    sum += currentObj;
                    currentObj = a[i];
                    curIndex = i;
                } else {
                    if (a[i] > currentObj) {
                        currentObj = a[i];
                    }
                }
            }
            sum += currentObj;
            out.printLine(sum);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;
        public int maxInArray = Integer.MIN_VALUE;
        Boolean isAllElementsInArryaSame = true;
        Boolean is2SameElementsConcurrent = false;
        private int firstPositivie = Integer.MAX_VALUE;
        private int firstNegative = Integer.MAX_VALUE;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        InputReader(String file) {
            try {
                br = new BufferedReader(new FileReader(file));
            } catch (FileNotFoundException ignored) {

            }
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

        public int[] nextIntArray(int n) {

            firstPositivie = n + 1;
            firstNegative = n + 1;

            isAllElementsInArryaSame = true;
            is2SameElementsConcurrent = false;
            maxInArray = Integer.MIN_VALUE;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
                if (a[i] > 0 && firstPositivie == n + 1) {
                    firstPositivie = i;
                }
                if (a[i] < 0 && firstNegative == n + 1) {
                    firstNegative = i;
                }
                if (a[i] > maxInArray) {
                    maxInArray = a[i];
                }
                if (i > 0 && a[i] != a[i - 1]) {
                    isAllElementsInArryaSame = false;
                }
                if (i > 0 && a[i] == a[i - 1]) {
                    is2SameElementsConcurrent = true;
                }
            }
            return a;
        }

    }
}

