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];
            for (int i = 0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
            int i = 0;
            int j = 0;
            long total = 0;
            boolean foundFirst = false;
            boolean foundSecond = false;
            while (i < arr.length && j < arr.length) {
                while (i < arr.length && arr[i] <= 0) {
                    i++;
                }
                if (i == arr.length) {
                    break;
                }

                int posEl = arr[i];
                while (i < arr.length && arr[i] > 0) {
                    posEl = Math.max(arr[i], posEl);
                    i++;
                }
                //System.out.println("Adding pos " + posEl);
                total += posEl;
                foundFirst = true;

                while (j < arr.length && arr[j] >= 0) {
                    j++;
                }
                if (j == arr.length) {
                    break;
                }

                int negEl = arr[j];
                while (j < arr.length && arr[j] < 0) {
                    negEl = Math.max(arr[j], negEl);
                    j++;
                }
                //System.out.println("Adding neg " + negEl);
                total += negEl;
                foundSecond = true;
            }

            System.out.println(foundFirst && foundSecond ? total : -1);
        }
    }
}
