#include <bits/stdc++.h>
using namespace std;
int ad[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};
struct Cell {
  int x;
  int y;
};
void dfs(Cell c, int m, int n, int k, vector<string>& maze, bool check[][500]) {
  stack<Cell> stk;
  int count = 0;
  stk.push(c);
  check[c.x][c.y] = true;
  while (!stk.empty() && count < k) {
    int x = stk.top().x, y = stk.top().y;
    for (int i = 0; i < 4; ++i) {
      c.x = x + ad[i][0];
      c.y = y + ad[i][1];
      if (c.x >= 0 && c.x < m && c.y >= 0 && c.y < n && maze[c.x][c.y] != '#' &&
          !check[c.x][c.y]) {
        stk.push(c);
        check[c.x][c.y] = true;
        break;
      }
    }
    if (stk.top().x == x && stk.top().y == y) {
      stk.pop();
      maze[x][y] = 'X';
      ++count;
    }
  }
}
int main() {
  vector<string> maze;
  bool check[500][500] = {false};
  int m, n, k;
  Cell c;
  bool found = false;
  string tmp;
  cin >> m >> n >> k;
  cin.ignore();
  for (int i = 0; i < m; ++i) {
    getline(cin, tmp);
    maze.push_back(tmp);
    if (!found && maze[i].find_first_of('.') != -1) {
      c.x = i;
      c.y = maze[i].find_first_of('.');
      found = true;
    }
  }
  dfs(c, m, n, k, maze, check);
  for (int i = 0; i < m; ++i) cout << maze[i] << endl;
  return 0;
}
