#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
vector<string> matrix;
vector<vector<bool>> check;
long long X[4] = {0, 1, 0, -1};
long long Y[4] = {-1, 0, 1, 0};
bool isValid(long long i, long long j) {
  if (i >= 0 && j >= 0 && i < n && j < m)
    return true;
  else
    return false;
}
void dfs(long long i, long long j) {
  check[i][j] = true;
  for (long long k = 0; k < 4; k++) {
    long long newX = i + X[k];
    long long newY = j + Y[k];
    if (isValid(newX, newY) && check[newX][newY] == false &&
        matrix[newX][newY] == '.') {
      dfs(newX, newY);
    }
  }
  if (k > 0) {
    matrix[i][j] = 'X';
    k--;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> k;
  vector<bool> temp(m, false);
  for (long long i = 0; i < n; i++) {
    string x;
    cin >> x;
    matrix.push_back(x);
    check.push_back(temp);
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (check[i][j] == false && matrix[i][j] == '.') dfs(i, j);
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cout << matrix[i][j];
    }
    cout << endl;
  }
  return 0;
}
