#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
};
int n, m, k, dots = 0;
char grid[502][502];
bool vis[502][502];
bool ok(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] &&
          grid[x][y] == '.');
}
void print() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << grid[i][j];
    }
    cout << endl;
  }
}
void dfs(point start) {
  stack<point> s;
  s.push(start);
  int ans = dots - k;
  while (!s.empty()) {
    point top = s.top(), nxt;
    s.pop();
    if (vis[top.x][top.y]) continue;
    vis[top.x][top.y] = true;
    --ans;
    if (!ans) return;
    nxt.x = top.x - 1, nxt.y = top.y;
    if (ok(nxt.x, nxt.y)) s.push(nxt);
    nxt.x = top.x + 1, nxt.y = top.y;
    if (ok(nxt.x, nxt.y)) s.push(nxt);
    nxt.x = top.x, nxt.y = top.y - 1;
    if (ok(nxt.x, nxt.y)) s.push(nxt);
    nxt.x = top.x, nxt.y = top.y + 1;
    if (ok(nxt.x, nxt.y)) s.push(nxt);
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == '.') ++dots;
    }
  }
  point start;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == '.') {
        start.x = i;
        start.y = j;
        break;
      }
    }
  }
  dfs(start);
  for (int i = 0; i < n && k; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!vis[i][j] && grid[i][j] == '.') grid[i][j] = 'X', --k;
    }
  }
  print();
  return 0;
}
