public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());
        k = Integer.parseInt(st.nextToken());
        isEmpty = new boolean[n*m];
        isVisited = new boolean[n*m];

        int first = -1;
        for(int i=0; i<n; i++){
            String str = br.readLine();
            for(int j=0; j<m; j++){
                if(str.charAt(j)=='.'){
                    isEmpty[i*m+j]=true;
                    s++;
                    if(first<0) first=i*m+j;
                }
            }
        }
        dfs(first);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(isEmpty[i*m+j]){
                    if(k==0 || isVisited[i*m+j]) System.out.print("."); else{
                        System.out.print("X");
                        k--;
                    }
                }else{
                    System.out.print("#");
                }
            }
            System.out.println();
        }
    }