import java.util.*;

import static java.lang.System.*;

public class Main
{
    public static void main(String[] args) {
        Scanner s = new Scanner(in);
        long t = s.nextInt();
        s.nextLine();

        while (t-- > 0) {
            int n = s.nextInt();
            long sum = 0;
            boolean isPositive = false;
            long largest = 0;
            for (int i = 0; i < n; i++) {
                long temp = s.nextLong();
                if (largest == 0) {
                    isPositive = temp > 0;
                    largest = temp;
                }
                if (temp > 0 != isPositive) {
                    sum += largest;
                    isPositive = temp > 0;
                    largest = temp;
                }
                if (temp > largest) largest = temp;
            }
            if (n > 1) {
                sum += largest;
            }
            out.println(sum);
        }
    }
}