#include <bits/stdc++.h>
using namespace std;
int n, m, k, dotx, doty;
char t[502][502];
int vis[502][502];
int x[4] = {0, -1, 0, 1};
int y[4] = {1, 0, -1, 0};
void dfs(int r, int c) {
  if (r >= n || r < 0 || c >= m || c < 0 || t[r][c] == '#' || vis[r][c]) return;
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) {
    dfs(r + x[i], c + y[i]);
  }
  if (k > 0) {
    k--;
    t[r][c] = 'X';
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> t[i][j];
      if (t[i][j] == '.') {
        dotx = i;
        doty = j;
      }
    }
  dfs(dotx, doty);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << t[i][j];
    }
    cout << '\n';
  }
}
