#include <bits/stdc++.h>
using namespace std;
long long int m, n, k, s;
char maze[501][501];
void solve();
void dfs(long long int i, long long int j) {
  if (k >= s) return;
  maze[i][j] = '1';
  k++;
  long long int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
  for (long long int k = 0; k < 4; k++) {
    long long int a = i + dx[k], b = j + dy[k];
    if (a >= 0 && a < m && b >= 0 && b < n && maze[a][b] == '.') dfs(a, b);
  }
}
int main() { solve(); }
void solve() {
  cin >> m >> n >> k;
  for (long long int i = 0; i < m; i++) cin >> maze[i];
  s = 0;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++)
      if (maze[i][j] == '.') s++;
  }
  s = s - k;
  k = 0;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++)
      if (maze[i][j] == '.') {
        dfs(i, j);
        break;
      }
  }
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++) {
      if (maze[i][j] == '1')
        cout << ".";
      else if (maze[i][j] == '.')
        cout << "X";
      else
        cout << "#";
    }
    cout << "\n";
  }
}
