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();
            long sum = 0;
            int s = 0;

            for(int j = 0; j < n; ++j) {
                int a = in.nextInt();

                if(j == n - 1 && (s > 0) != (a > 0)){
                    sum += a;
                }

                if((s > 0) != (a > 0) || (j == n - 1) || (j == 0)) {
                    sum += s;
                    System.out.println(s);
                    s = a;
                }
                else if(a > s) {
                    s = a;
                }
            }
            System.out.println(sum);
            System.out.println(' ');
        }
    }
}
