#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 17;
const int maxN = 3e5;
char a[maxn][maxn];
int n, m, k, first, cnt, x = 1;
bool mark[maxN], flg;
vector<int> g[maxN];
set<int> brg;
void dfs(int v) {
  mark[v] = 1;
  if (flg == true) brg.insert(v);
  if (x == cnt - k) flg = true;
  x++;
  for (auto u : g[v])
    if (!mark[u]) dfs(u);
}
void make_graph() {
  int p = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      p++;
      if (a[i][j] == '#') continue;
      first = p;
      cnt++;
      if (a[i][j - 1] != '#' && j != 1)
        g[p].push_back(p - 1), g[p - 1].push_back(p);
      if (a[i][j + 1] != '#' && j != m)
        g[p].push_back(p + 1), g[p + 1].push_back(p);
      int d1 = p - (m - j) - (j - 1) - 1, d2 = p + (m - j) + (j - 1) + 1;
      if (d1 > 0 && a[i - 1][j] != '#' && i != 1)
        g[p].push_back(d1), g[d1].push_back(p);
      if (d2 > 0 && a[i + 1][j] != '#' && i != n)
        g[p].push_back(d2), g[d2].push_back(p);
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  make_graph();
  dfs(first);
  int p = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      p++;
      if (a[i][j] == '#')
        cout << '#';
      else {
        if (brg.find(p) != brg.end())
          cout << 'X';
        else
          cout << '.';
      }
    }
    cout << endl;
  }
  return 0;
}
