#include <bits/stdc++.h>
using namespace std;
typedef struct node {
  char ch;
  int vit;
} node;
vector<vector<node> > vc;
int dir[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
bool isGo(int x, int y, int n, int m) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
void print(int n, int m) {
  cout << '\n';
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cout << vc[i][j].ch;
    cout << '\n';
  }
  cout << '\n';
  return;
}
int dfs(int x, int y, int n, int m, int k) {
  int nx, ny;
  vc[x][y].vit = 1;
  k--;
  if (!k) return 0;
  for (int i = 0; i < 4; ++i) {
    nx = x + dir[i][0];
    ny = y + dir[i][1];
    if (isGo(nx, ny, n, m) && vc[nx][ny].ch == '.' && vc[nx][ny].vit == 0)
      k = dfs(nx, ny, n, m, k);
    if (!k) break;
  }
  return k;
}
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n, m, k, ok = 0;
  cin >> n >> m >> k;
  vc = vector<vector<node> >(n, vector<node>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> vc[i][j].ch;
      vc[i][j].vit = 0;
      if (vc[i][j].ch == '.') ok++;
    }
  }
  k = ok - k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (vc[i][j].ch == '.') {
        k = dfs(i, j, n, m, k);
        break;
      }
    }
    if (!k) break;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (vc[i][j].ch == '.' && vc[i][j].vit == 0)
        cout << 'X';
      else
        cout << vc[i][j].ch;
    }
    cout << '\n';
  }
  return 0;
}
