#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int s = m * n;
  vector<vector<char> > tab;
  tab.resize(n);
  vector<vector<int> > graph;
  graph.resize(m * n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      tab[i].push_back(c);
      if (c == '.') {
        if (i > 0 && tab[i - 1][j] == '.') {
          graph[i * m + j].push_back((i - 1) * m + j);
          graph[(i - 1) * m + j].push_back(i * m + j);
        }
        if (j > 0 && tab[i][j - 1] == '.') {
          graph[i * m + j].push_back(i * m + j - 1);
          graph[i * m + j - 1].push_back(i * m + j);
        }
      }
      if (c == '#') s--;
    }
  int count = 0;
  queue<int> q;
  int cur = 0;
  vector<bool> used(m * n, false);
  while (tab[cur / m][cur % m] == '#') cur++;
  q.push(cur);
  used[cur] = true;
  while (!q.empty()) {
    cur = q.front();
    q.pop();
    count++;
    if (count > s - k) tab[cur / m][cur % m] = 'X';
    for (int i = 0; i < graph[cur].size(); ++i) {
      if (!used[graph[cur][i]]) {
        used[graph[cur][i]] = true;
        q.push(graph[cur][i]);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << tab[i][j];
    }
    cout << endl;
  }
  return 0;
}
