#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = 2147483647;
long long n, m, k;
char a[505][505];
bool visited[505][505];
long long s = 0;
long long numofvisited = 0;
bool check(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return false;
  return true;
}
void dfs(int i, int j) {
  if (visited[i][j] || !check(i, j) || a[i][j] == '#') return;
  if (s - k == numofvisited) return;
  visited[i][j] = true;
  numofvisited++;
  dfs(i, j - 1);
  dfs(i, j + 1);
  dfs(i + 1, j);
  dfs(i - 1, j);
  return;
}
int main() {
  memset(visited, false, sizeof(visited));
  cin >> n >> m >> k;
  for (__typeof(0) i = (0); i < (n); ++i) {
    for (__typeof(0) j = (0); j < (m); ++j) {
      cin >> a[i][j];
      if (a[i][j] == '.') s++;
    }
  }
  for (__typeof(0) i = (0); i < (n); ++i) {
    for (__typeof(0) j = (0); j < (m); ++j) {
      dfs(i, j);
    }
  }
  for (__typeof(0) i = (0); i < (n); ++i) {
    for (__typeof(0) j = (0); j < (m); ++j) {
      if (a[i][j] == '.' && !visited[i][j]) {
        a[i][j] = 'X';
      }
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
