import java.util.Scanner;

public class C1343 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while (t-- > 0) {
            int n = scanner.nextInt();
            int[] arr = new int[n];

            arr[0] = scanner.nextInt();
            int current = arr[0];
            long total = 0;
            boolean found = false;
            for (int i = 1; i < n; i++) {
                found = true;
                arr[i] = scanner.nextInt();
                if (isSame(arr[i], arr[i - 1])) {
                    current = Math.max(current, arr[i]);
                } else {
                    total += current;
                    current = arr[i];
                }
                //System.out.println("TOTAL " + total);
            }

            if (isSame(current, arr[n - 1]) || !found) {
                total += current;
                //System.out.println("TOTAL " + total);
            }

            System.out.println(total);
        }
    }

    private static boolean isSame(int i, int j) {
        return ((i > 0 && j > 0) || (i < 0 && j < 0));
    }
}
