#include <bits/stdc++.h>
using namespace std;
char a[505][505];
bool visited[505][505];
int n, m, k;
vector<pair<int, int> > v;
bool safe(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] == '.') return true;
  return false;
}
void dfs(int i, int j) {
  visited[i][j] = true;
  v.push_back(make_pair(i, j));
  if (safe(i + 1, j) && !visited[i + 1][j]) dfs(i + 1, j);
  if (safe(i - 1, j) && !visited[i - 1][j]) dfs(i - 1, j);
  if (safe(i, j - 1) && !visited[i][j - 1]) dfs(i, j - 1);
  if (safe(i, j + 1) && !visited[i][j + 1]) dfs(i, j + 1);
}
int main() {
  int p, q, f = 0;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.' && f == 0) {
        p = i;
        q = j;
        f = 1;
      }
    }
  }
  dfs(p, q);
  for (int i = v.size() - 1; k > 0; i--, k--) {
    a[v[i].first][v[i].second] = 'X';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
