#include <bits/stdc++.h>
using namespace std;
char s[505][505];
long long int vis[505][505];
long long int has;
long long int n, m, k;
long long int cnt = 0;
void dfs(long long int i, long long int j, long long int tot) {
  if (s[i][j] == '#') {
    return;
  }
  if (vis[i][j] == 1) {
    return;
  }
  if (i < 0 || j < 0 || i >= n || j >= m) {
    return;
  }
  if (cnt >= tot) {
    return;
  }
  vis[i][j] = 1;
  cnt++;
  dfs(i + 1, j, tot);
  dfs(i - 1, j, tot);
  dfs(i, j - 1, tot);
  dfs(i, j + 1, tot);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  long long int tot = n * m - k;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> s[i][j];
      if (s[i][j] == '#') {
        has++;
      }
    }
  }
  tot -= has;
  long long int x, y;
  long long int f = -1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        x = i;
        y = j;
        f = 1;
        break;
      }
    }
    if (f == 1) break;
  }
  dfs(x, y, tot);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (s[i][j] != '#') {
        if (vis[i][j] == 1) {
          s[i][j] = '.';
        } else
          s[i][j] = 'X';
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cout << s[i][j];
    }
    cout << endl;
  }
  return 0;
}
