#include <bits/stdc++.h>
using namespace std;
int row, col, k;
const int MAX = 550;
char mat[MAX][MAX];
bool vis[MAX][MAX];
int main_cnt;
int temp_cnt;
void DFS(int i, int j) {
  if (main_cnt == 0) return;
  if (mat[i][j] == '#') return;
  if (vis[i][j] == true) return;
  main_cnt--;
  vis[i][j] = true;
  if ((i + 1 >= 0 && i + 1 < row && j >= 0 && j <= col) ? 1 : 0) DFS(i + 1, j);
  if ((i - 1 >= 0 && i - 1 < row && j >= 0 && j <= col) ? 1 : 0) DFS(i - 1, j);
  if ((i >= 0 && i < row && j + 1 >= 0 && j + 1 <= col) ? 1 : 0) DFS(i, j + 1);
  if ((i >= 0 && i < row && j - 1 >= 0 && j - 1 <= col) ? 1 : 0) DFS(i, j - 1);
}
int main() {
  while (cin >> row >> col >> k) {
    memset(mat, '#', sizeof(mat));
    memset(vis, false, sizeof(vis));
    int x = 0, y = 0;
    int s = 0;
    for (int M = 0; M < row; M++) {
      for (int K = 0; K < col; K++) {
        cin >> mat[M][K];
        if (mat[M][K] == '.') {
          s++;
          x = M;
          y = K;
        }
      }
    }
    main_cnt = s - k;
    DFS(x, y);
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < col; j++) {
        if (mat[i][j] == '.' && vis[i][j] == false) {
          mat[i][j] = 'X';
        }
        cout << mat[i][j];
      }
      cout << endl;
    }
    cout << endl << endl;
    ;
  }
  return 0;
}
