#include <bits/stdc++.h>
using namespace std;
int n, m, k, c, x, y, rem;
char a[501][501];
int v[501][501];
void dfs(int x, int y) {
  if (rem == 0 || a[x][y] == '#') return;
  if (x < 0 || x >= n || y < 0 || y >= m || v[x][y] == 1) return;
  v[x][y] = 1;
  rem--;
  dfs(x + 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
  dfs(x - 1, y);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        c++;
        if (c == 1) {
          x = i;
          y = j;
        }
      }
    }
  rem = c - k;
  dfs(x, y);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == 0 && a[i][j] == '.')
        cout << 'X';
      else
        cout << a[i][j];
    }
    cout << '\n';
  }
}
