public static void main(String[] args) {
    
        Scanner input = new Scanner(System.in);
        int cases = 1;
        while (true) {
        
            // input
            m = input.nextInt();
            n = input.nextInt();
            if (m + n == 0) return;
            
            x1 = input.nextInt();
            y1 = input.nextInt();
            x2 = input.nextInt();
            y2 = input.nextInt();
            x3 = input.nextInt();
            y3 = input.nextInt();
            
            // get the stops
            int size = n * m;
            s1 = size / 4;
            s2 = size / 2;
            s3 = 3 * size / 4;
            s4 = size;
            steps = 0;
            
            // solve it
            grid = new int[m][n]; // 1 is default, 2 for curr, 3 for visited, - for station
            for (int i = 0; i < m; ++i)
                for (int j = 0; j < n; ++j)
                    grid[i][j] = 1;
            // set the stations
            grid[x1][y1] = -1;
            grid[x2][y2] = -1;
            grid[x3][y3] = -1;
            grid[0][1] = -1;
            
            // make the first move
            int routes = solve(0, 0, 1);
            
            // output
            System.out.printf("Case %d: %d\n", cases, routes);
            ++cases;
        }
    }