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);
    }

    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 sumPos = 0;
            long lenPos = pos > 0 ? 1 : 0;;
            long currentMaxPos = a[0];
            for (int i = pos; i < n && i >= 0; i++) {
                if (i > pos && oppositeSigns(a[i - 1], a[i])){
                    sumPos += currentMaxPos;
                    currentMaxPos = a[i];
                    lenPos += 1;
                } else {
                    currentMaxPos = Math.max(currentMaxPos, a[i]);
                }
            }
            sumPos += currentMaxPos;


            long sumNeg = 0;
            long lenNeg = neg > 0 ? 1 : 0;
            long currentMaxNeg = a[0];
            for (int i = neg; i < n && i >= 0; i++) {
                if (i > neg && (oppositeSigns(a[i - 1], a[i]))){
                    sumNeg += currentMaxNeg;
                    currentMaxNeg = a[i];
                    lenNeg += 1;
                } else {
                    currentMaxNeg = Math.max(currentMaxNeg, a[i]);
                }
            }
            sumNeg += currentMaxNeg;




            if (lenPos == lenNeg){
                System.out.println(Math.max(sumNeg, sumPos));
            } else if (lenPos > lenNeg){
                System.out.println(sumPos);
            } else {
                System.out.println(sumNeg);
            }


        }
    }
}

