import java.util.*;
public class AlternatingSubsequence {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int t = 0; t < T; t++) {
            int N = in.nextInt();
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = in.nextInt();
            }
            int max = 0;
            long sum = 0;
            for (int i = 0; i < N; i++) {
                if (i == 0 || Integer.signum(arr[i]) != Integer.signum(arr[i - 1])) {
                    sum += max;
                    max = arr[i];
                }
                max = Math.max(max, arr[i]);
            }
            sum += max;
            System.out.println(sum);
        }
    }
}