import java.io.*;
import java.lang.reflect.Array;
import java.util.*;


public class Main {


    static Long max = (long) (2 * 10E5);
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    static Long[] readLongArray() throws IOException {
        return Arrays.stream(br.readLine().split("\\s+")).map(Long::parseLong).toArray(Long[]::new);
    }

    static Integer[] readIntArray() throws IOException {
        return Arrays.stream(br.readLine().split("\\s+")).map(Integer::parseInt).toArray(Integer[]::new);
    }

    static int readInt() throws IOException {
        return Integer.parseInt(br.readLine());
    }

    static long readLong() throws IOException {
        return Long.parseLong(br.readLine());
    }


    static boolean oppositeSigns(long x, long y) {
        return ((x ^ y) < 0);
    }

    static long[] count(long[] a, int i) {
        long sum = 0, currentMax = Long.MIN_VALUE, len = (i >= 0) ? 1 : 0;
        for (int j = i; j < a.length && j >= 0; j++) {
            if (j > i && oppositeSigns(a[j - 1], a[j])) {
                sum += currentMax;
                currentMax = a[j];
                len += 1;
            } else
                currentMax = Math.max(currentMax, a[j]);
        }
        sum += currentMax;
        return new long[]{len, sum};
    }

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

        int _t = scanner.nextInt();
        for (int t = 0; t < _t; t++) {
            int n = scanner.nextInt();
            long[] a = new long[n];
            int pos = -1, neg = -1;
            for (int i = 0; i < n && i >= 0; i++) {
                a[i] = scanner.nextLong();
                if (pos < 0 && a[i] >= 0)
                    pos = i;
                if (neg < 0 && a[i] < 0)
                    neg = i;
            }

            long[] resNeg = count(a, neg);
            long[] resPos = count(a, pos);

            if (resPos[0] == resNeg[0]) {
                System.out.println(Math.max(resPos[1], resNeg[1]));
            } else if (resPos[0] > resNeg[0]) {
                System.out.println(resPos[1]);
            } else {
                System.out.println(resNeg[1]);
            }


        }
    }
}

