#include <bits/stdc++.h>
using namespace std;
const int kMaxn = 501;
const int kDx[4] = {-1, 0, 1, 0};
const int kDy[4] = {0, -1, 0, 1};
int n, m, k, empty_cells;
string maze[kMaxn];
bool visited[kMaxn][kMaxn];
void Dfs(int x, int y) {
  visited[x][y] = true;
  --empty_cells;
  if (empty_cells < k) {
    maze[x][y] = 'X';
  }
  for (int i = 0; i < 4; ++i) {
    int tx = x + kDx[i];
    int ty = y + kDy[i];
    if (tx < 0 || tx >= n || ty < 0 || ty >= m || maze[tx][ty] != '.' ||
        visited[tx][ty]) {
      continue;
    }
    Dfs(tx, ty);
  }
}
int main() {
  cin >> n >> m >> k;
  empty_cells = 0;
  for (int i = 0; i < n; ++i) {
    cin >> maze[i];
    empty_cells += count(maze[i].begin(), maze[i].end(), '.');
  }
  int x = -1, y = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (maze[i][j] == '.') {
        x = i, y = j;
      }
    }
  }
  Dfs(x, y);
  for (int i = 0; i < n; ++i) {
    cout << maze[i] << endl;
  }
  return 0;
}
