#include <bits/stdc++.h>
using ll = long long;
using namespace std;
struct Node {
  char value = '#';
  bool used = false;
  bool in_dfs = false;
  vector<Node*> neighbours;
};
int am = 0;
void dfs(Node& v) {
  if (am == 0) {
    return;
  }
  v.in_dfs = true;
  --am;
  for (auto u : v.neighbours) {
    if (am == 0) {
      return;
    }
    if (!u->used) {
      u->used = true;
      dfs(*u);
    }
  }
}
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<vector<Node>> a(n + 2, vector<Node>(m + 2));
  ll root_i, root_j;
  char value;
  ll amount_of_points = 0;
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; j <= m; ++j) {
      cin >> value;
      if (value == '.') {
        ++amount_of_points;
        a[i][j].value = value;
        root_i = i;
        root_j = j;
      }
    }
  }
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; j <= m; ++j) {
      if (a[i][j].value == '.') {
        if (a[i][j + 1].value == '.') {
          a[i][j].neighbours.push_back(&a[i][j + 1]);
        }
        if (a[i][j - 1].value == '.') {
          a[i][j].neighbours.push_back(&a[i][j - 1]);
        }
        if (a[i + 1][j].value == '.') {
          a[i][j].neighbours.push_back(&a[i + 1][j]);
        }
        if (a[i - 1][j].value == '.') {
          a[i][j].neighbours.push_back(&a[i - 1][j]);
        }
      }
    }
  }
  a[root_i][root_j].used = true;
  ll amount = amount_of_points - k;
  am = amount;
  dfs(a[root_i][root_j]);
  for (ll i = 1; i <= n; ++i) {
    for (ll j = 1; j <= m; ++j) {
      if (a[i][j].value == '.' && !a[i][j].in_dfs) {
        cout << 'X';
      } else {
        cout << a[i][j].value;
      }
    }
    cout << '\n';
  }
  return 0;
}
