import java.util.*;

public class Main {

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        while(p-->0)
        {
                int n = sc.nextInt();
                boolean isNeg = false;
                int x = sc.nextInt();
                int max = x;
                long sum = 0L;
                if (x < 0)
                isNeg = true;
                for (int i = 0; i < n - 1; i++) {
                    x = sc.nextInt();
                    if (isNeg && x > 0 || !isNeg && x < 0) {
                        isNeg = !isNeg;
                        sum += max;
                        max = x;
                    } else max = Math.max(max, x);

                }
                sum += max;
                System.out.println(sum);
        }
    }
}