import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int negSize = 0;
            long negSum = 0;
            int posSize = 0;
            long posSum = 0;
            for (int j = 0; j < n; j++) {
                int v = in.nextInt();
                if (v > 0) {
                    if (negSize + 1 > posSize) {
                        posSize = negSize + 1;
                        posSum = negSum + v;
                    } else if (negSize + 1 == posSize) {
                        posSum = Math.max(posSum, negSum + v);
                    }
                } else {
                    if (posSize + 1 > negSize) {
                        negSize = posSize + 1;
                        negSum = posSum + v;
                    } else if (posSize + 1 == negSize) {
                        negSum = Math.max(negSum, posSum + v);
                    }
                }
            }
            if (negSize > posSize) {
                System.out.println(negSum);
            } else if (negSize < posSize) {
                System.out.println(posSum);
            } else {
                System.out.println(Math.max(negSum, posSum));
            }
        }
    }
}