#include <bits/stdc++.h>
using namespace std;
int k, n, m;
char c[500 + 10][500 + 10];
bool mark[500 + 10][500 + 10];
int pointer[2];
void dfs(int x, int y) {
  mark[x][y] = true;
  if (x - 1 >= 0 && mark[x - 1][y] == false) {
    dfs(x - 1, y);
  }
  if (y - 1 >= 0 && mark[x][y - 1] == false) {
    dfs(x, y - 1);
  }
  if (y + 1 <= m - 1 && mark[x][y + 1] == false) {
    dfs(x, y + 1);
  }
  if (x + 1 <= n - 1 && mark[x + 1][y] == false) {
    dfs(x + 1, y);
  }
  if (k > 0) {
    c[x][y] = 'X';
    k--;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '.') {
        pointer[0] = i;
        pointer[1] = j;
      } else {
        mark[i][j] = true;
      }
    }
  }
  dfs(pointer[0], pointer[1]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << c[i][j];
    }
    cout << endl;
  }
  return 0;
}
