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:

import java.io.*;
import java.util.*;
import java.math.*;

public class Main { 
    
    static class Point{
        int x, y;
        Point(int x,int y){
            this.x = x;
            this.y = y;
        }
    }
    static int k;
    static ArrayList<Integer>[] grp ;
    static int[] dep;
    static int[] parent;   
    static boolean[] vis;
    static ArrayList<Integer> list;
    public static void main(String[] args) throws java.lang.Exception { 
        //Reader pm =new Reader(); 
        Scanner pm = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = pm.nextInt();
        int m = pm.nextInt();
        k = pm.nextInt();
        char[][] c = new char[n][m];
        int[][] d = new int[n][m];
        int cnt = 0;
        HashMap<Integer, Point> org = new HashMap<>();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                d[i][j] = cnt;
                org.put(cnt, new Point(i,j));
                cnt++;
            }
        }
        //Point[][] pc = Point[n][m];
        for(int i=0;i<n;i++){
            String s = pm.next();
            for(int j=0;j<m;j++){
                c[i][j] = s.charAt(j);
                //System.out.print(d[i][j]+" ");
            }
            //System.out.println();
        }
        grp = new ArrayList[n*m];
        for(int i=0;i<n*m;i++){
            grp[i] = new ArrayList<>();
        }
        vis = new boolean[n*m];
        dep = new int[n*m];
        parent = new int[n*m];
        list = new ArrayList<>();
        Arrays.fill(parent, -1);
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(c[i][j] == '.'){
                    // System.out.println(i+" "+j);
                    // System.out.println("dig "+d[i][j]);
                    if(i-1 >= 0){
                        if(c[i-1][j] == '.'){
                            //System.out.println(1);
                            if(!grp[d[i][j]].contains(d[i-1][j]))
                                grp[d[i][j]].add(d[i-1][j]);
                            if(!grp[d[i-1][j]].contains(d[i][j]))
                                grp[d[i-1][j]].add(d[i][j]);
                        }
                    } 
                    if(i+1 <= n-1){
                        if(c[i+1][j] == '.'){
                            //System.out.println(2);
                            if(!grp[d[i][j]].contains(d[i+1][j]))
                                grp[d[i][j]].add(d[i+1][j]);
                            if(!grp[d[i+1][j]].contains(d[i][j]))
                                grp[d[i+1][j]].add(d[i][j]);
                        }
                    }
                    if(j-1 >= 0){
                        if(c[i][j-1] == '.'){
                            //System.out.println(3);
                            if(!grp[d[i][j]].contains(d[i][j-1]))
                                grp[d[i][j]].add(d[i][j-1]);
                            if(!grp[d[i][j-1]].contains(d[i][j]))
                                grp[d[i][j-1]].add(d[i][j]);
                        }
                    } 
                    if(j+1 <= m-1){
                        if(c[i][j+1] == '.'){
                            //System.out.println(4);
                            if(!grp[d[i][j]].contains(d[i][j+1]))
                                grp[d[i][j]].add(d[i][j+1]);
                            if(!grp[d[i][j+1]].contains(d[i][j]))
                                grp[d[i][j+1]].add(d[i][j]);
                        }
                    }
                }
            }
        }
        int first = 0;
        first = 0;
        for(int i=0;i<grp.length;i++){
             //System.out.println(i+" -> "+grp[i]);
            if(grp[i].size() != 0){
                first = i;
                break;
            }    
        }
        dfs(first,first,0,c,org);
        int plc = 0;
        while(k-- > 0){
            
            int last = list.get(list.size()-1-plc);
            //System.out.println(list+" "+last);
            int x = org.get(last).x;
            int y = org.get(last).y;
            c[x][y] = 'X';
            plc++;
            // for(int i=0;i<grp.length;i++){
            //     // if(i == last){
            //     //     grp[i].clear();
            //     // }
            //     // for(int j=0;j<grp[i].size();j++){
            //     //     if(grp[i].contains(last)){
            //     //         grp[i].remove(last);
            //     //     }
            //     // }
            //   // System.out.println(grp[i]);
            //     // if(grp[i].contains(last))
            //     //     grp[i].remove((Integer)last);
            // }
            // for(int i=0;i<grp.length;i++){
            //     System.out.println(grp[i]);
            // }
            //list.clear();
            //vis = new boolean[n*m];
        }
        //System.out.println(first);
        //dfs(first,first,0,c,org);
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
                System.out.print(c[i][j]+"");
            System.out.println();
        }
    }
    
    
    static void dfs(int v, int from, int depth,char[][] c,HashMap<Integer, Point> org) {
        //dep[v] = depth;
        //s[v] = 1;
        vis[v] = true;
        list.add(v);
        for (int u : grp[v]) {
            if (u == from) continue;
            if(!vis[u])
                dfs(u, v, depth + 1, c,org);
            //parent[v] = u;
            //s[v] += s[u];
            //System.out.println(u+" -> "+v);
            // if(k > 0 && parent[u] == -1){
            //     //1dep[u] = 1;
            //     k--;
            //     parent[v] = -1;
            //     int x = org.get(u).x;
            //     int y = org.get(u).y;
            //     c[x][y] = 'X';
            // }

            // for(int i=0;i<c.length;i++){
            //     for(int j=0;j<c[0].length;j++)
            //         System.out.print(c[i][j]+"");
            //     System.out.println();
       // }
        }
    }
    
    public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) 
    { 
        // Create a list from elements of HashMap 
        List<Map.Entry<Integer, Integer> > list = 
               new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); 
  
        // Sort the list 
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { 
            public int compare(Map.Entry<Integer, Integer> o1,  
                               Map.Entry<Integer, Integer> o2) 
            { 
                return (o1.getValue()).compareTo(o2.getValue()); 
            } 
        }); 
          
        // put data from sorted list to hashmap  
        HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); 
        for (Map.Entry<Integer, Integer> aa : list) { 
            temp.put(aa.getKey(), aa.getValue()); 
        } 
        return temp; 
    } 
    static class Reader { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String readLine() throws IOException 
        { 
            byte[] buf = new byte[64]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nextInt() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nextLong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double nextDouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    }
}