#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
char arr[500][500];
int vis[500][500];
long long int n, m, k;
int dfs(int x, int y) {
  vis[x][y] = 2;
  if (x != 0) {
    if ((vis[x - 1][y] == 0) && (arr[x - 1][y] == '.')) {
      dfs(x - 1, y);
    }
  }
  if (y != 0) {
    if ((vis[x][y - 1] == 0) && (arr[x][y - 1] == '.')) {
      dfs(x, y - 1);
    }
  }
  if ((x + 1) != n) {
    if ((vis[x + 1][y] == 0) && (arr[x + 1][y] == '.')) {
      dfs(x + 1, y);
    }
  }
  if ((y + 1) != m) {
    if ((vis[x][y + 1] == 0) && (arr[x][y + 1] == '.')) {
      dfs(x, y + 1);
    }
  }
  vis[x][y] = 1;
  v.push_back(make_pair(x, y));
  return 0;
}
int main() {
  cin >> n >> m >> k;
  int rx, ry;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '.') {
        rx = i;
        ry = j;
      }
    }
  }
  dfs(rx, ry);
  for (int i = 0; i < k; i++) {
    arr[v[i].first][v[i].second] = 'X';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << arr[i][j];
    }
    cout << endl;
  }
  return 0;
}
