Problem: Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.

Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

Input

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.

Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Output

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").

It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

Examples

Input

3 4 2
#..#
..#.
#...


Output

#.X#
X.#.
#...


Input

5 4 5
#...
#.#.
.#..
...#
.#.#


Output

#XXX
#X#.
X#..
...#
.#.#

Solution (in JAVA):

Solution:
// Assignment 1 CP 104C
import java.util.*;

public class Maze {
    static boolean[][] visited;
    static char[][] maze;
    static int[] dx = {0, 0, -1, 1};
    static int[] dy = {1, -1, 0, 0};
    static int diff = 0;
    static int numVertices = 0;
    static int n, m, k, x = 0;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt(); sc.nextLine();
        maze = new char[n][m];
        visited = new boolean[n][m];
        int startR = -1;
        int startC = -1;
        // Parse and fill in our maze. 
        for(int row = 0; row < maze.length; row++) {
            String curr = sc.nextLine();
            for(int col = 0; col < maze[0].length; col++) {
                maze[row][col] = curr.charAt(col);
                if (maze[row][col] == '.') {
                    numVertices++;
                    startR = row;
                    startC = col;
                }
            }
        }

        DFS(startR, startC);
        for (int r = 0; r < n; r++) {
            for (int c = 0; c < m; c++) {
                if (!visited[r][c] && maze[r][c] == '.'
                    && k != 0) {
                    maze[r][c] = 'X';
                }
                System.out.print(maze[r][c]);
            }
            System.out.println();
        }

    }

    // private static char[][] addWalls(char[][] maze, int k, int n, int m) {
    //     HashMap<String, ArrayList<String>> adjLists_dict = new HashMap<String, ArrayList<String>>();
    //     for(int row = 0; row < maze.length; row++) {
    //         for(int col = 0; col < maze[0].length; col++) {
    //             if(maze[row][col] == '.') {
    //                 String c = String.valueOf(row) + ", " + String.valueOf(col);
    //                 adjLists_dict.put(c, getNeighborList(maze, row, col));
    //             }
    //         }
    //     }
    //     // now iterate over all our keys and whoever has only one neighbor gets cut. 
    //     String[] s = new String[adjLists_dict.keySet().size()];
    //     String[] keys = adjLists_dict.keySet().toArray(s);

    //     for(int i = 0; i < keys.length && k != 0; i++) {
    //         if(adjLists_dict.get(keys[i]).size() == 1) {
    //             // if the number of neighbors is of size one, mark an x on keys[i] and decrease k
    //             int row = Character.getNumericValue(keys[i].charAt(0)) ;
    //             int col = Character.getNumericValue(keys[i].charAt(keys[i].length() - 1)) ;
    //             maze[row][col] = 'X';
    //             k--;
    //         }
    //     }
    //     return maze;
    // }

    // private static ArrayList<String> getNeighborList(char[][] maze, int row, int col) {
    //     ArrayList<String> results = new ArrayList<>();
    //     // up 
    //     if(row - 1 > 0 && maze[row - 1][col] == '.') {
    //         String s = String.valueOf(row - 1) + ", " + String.valueOf(col);
    //         results.add(s);
    //     }
    //     // left
    //     if(col - 1 > 0 && maze[row][col - 1] == '.') {
    //         String s = String.valueOf(row) + ", " + String.valueOf(col - 1);
    //         results.add(s);
    //     }
    //     // right
    //     if(col + 1 < maze[0].length && maze[row][col + 1] == '.') {
    //         String s = String.valueOf(row) + ", " + String.valueOf(col + 1);
    //         results.add(s);
    //     }
    //     // down
    //     if(row + 1 < maze.length && maze[row + 1][col] == '.') {
    //         String s = String.valueOf(row + 1) + ", " + String.valueOf(col);
    //         results.add(s);
    //     }
    //     return results;
    // }

    private static void DFS(int r, int c) {
        if (diff == numVertices - k || k == 0)
            return;
        
        if (r < 0 || r >= n || c < 0 || c >= m || visited[r][c]) {
            return;
        }
        
        if (maze[r][c] == '.') {
            visited[r][c] = true;
            diff++;
 
            for (int i = 0; i < dx.length; i++)
                DFS(r + dx[i], c + dy[i]);
        }
    }
}