#include <bits/stdc++.h>
using namespace std;
inline void read_string_to_vector(vector<string> &vec) {
  string str;
  getline(cin, str);
  vec.push_back(str);
}
template <typename T>
inline void read_digit_to_vector(vector<T> &vec) {
  T t;
  cin >> t;
  vec.push_back(t);
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
long long n, m, k;
char mMas[504][504];
bool used[504][504];
bool li[504][504];
long long moff[4] = {-1, 1};
void DFSVisit(long long i, long long j) {
  used[i][j] = true;
  bool mli = false;
  for (register long long mi = 0; mi < 2; ++mi) {
    if (mMas[i][j + moff[mi]] == '.' && !used[i][j + moff[mi]]) {
      DFSVisit(i, j + moff[mi]);
      mli = !li[i][j + moff[mi]];
    }
    if (mMas[i + moff[mi]][j] == '.' && !used[i + moff[mi]][j]) {
      DFSVisit(i + moff[mi], j);
      mli = !li[i + moff[mi]][j];
    }
  }
  if (!mli && k) {
    --k;
    mMas[i][j] = 'X';
    li[i][j] = true;
  }
}
void mDFS() {
  for (register long long i = 0; i < 504; ++i)
    for (register long long j = 0; j < 504; ++j)
      if (mMas[i][j] == '.' && !used[i][j]) DFSVisit(i, j);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (register long long i = 0; i < n; ++i) cin >> &(mMas[i + 1][1]);
  mDFS();
  for (register long long i = 0; i < n; ++i) cout << (mMas[i + 1] + 1) << "\n";
  return 0;
}
