//package Problemset.Tag.DynamicProgramming;

import java.util.Scanner;

public class AlternatingSubsequence {

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

        int T = cin.nextInt();

        while (T-- > 0) {
            int n = cin.nextInt();
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = cin.nextInt();
            }
            long[] a = new long[n + 1];
            long max = Long.MIN_VALUE;
            a[0] = arr[0];
            for (int i = 0, j = i + 1; i < n - 1 && j < n - 1; j++) {
                if ((arr[i] < 0 && arr[j] < 0) || (arr[i] > 0 && arr[j] > 0)) {
                    max = Math.max(max, Math.max(arr[i], arr[j]));
                    a[i] = max;
                    if ((arr[j] < 0 && arr[j + 1] > 0) || (arr[j] > 0 && arr[j + 1] < 0)) {
                        a[j + 1] = arr[j + 1];
                    }
                } else {
                    if ((arr[i] < 0 && arr[i + 1] > 0) || (arr[i] > 0 && arr[i + 1] < 0)) {
                        a[i + 1] = arr[j];
                    }
                    i = j;
                    max = Long.MIN_VALUE;

                }
            }
            long sum = 0;
            long sum1 = 0;
            for (int i = 0; i < n - 1; i++) {
                sum1 += arr[i];
            }

            for (int i = 0; i < n; i++) {
                sum += a[i];
            }
            if (sum1 == sum) {
                System.out.println(sum1 + arr[n - 1]);
            } else
                System.out.println(sum);
        }
    }

}
