#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
int n, m, k, grad[MAXN][MAXN];
char v[MAXN][MAXN];
int test(int i, int j) {
  if (i < 1 || j < 1) return 0;
  if (i > n || j > m) return 0;
  return 1;
}
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int is_single(int x, int y) {
  int vec = 0;
  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (test(nx, ny) && v[nx][ny] == '.') ++vec;
  }
  return vec < 2;
}
void make_bfs(int x, int y) {
  if (k == 0) return;
  --k;
  v[x][y] = 'Z';
  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (test(nx, ny) && v[nx][ny] == '.') make_bfs(nx, ny);
  }
}
int get_s() {
  int rez = 0;
  for (int(i) = (1); (i) <= (n); ++(i))
    for (int(j) = (1); (j) <= (m); ++(j))
      if (v[i][j] == '.') ++rez;
  return rez;
}
int main() {
  cin >> n >> m >> k;
  cin.get();
  for (int i = 1; i <= n; ++i) cin.getline(v[i] + 1, MAXN);
  k = get_s() - k;
  for (int(i) = (1); (i) <= (n); ++(i))
    for (int(j) = (1); (j) <= (m); ++(j))
      if (v[i][j] == '.') make_bfs(i, j);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (v[i][j] == '.')
        v[i][j] = 'X';
      else if (v[i][j] == 'Z')
        v[i][j] = '.';
      cout << v[i][j];
    }
    cout << "\n";
  }
}
