#include <bits/stdc++.h>
using namespace std;
int n, m, ctr, s, k;
char a[1001][1001];
int visited[1001][1001];
int valid(int x, int y) {
  if (x <= n && x >= 1 && y <= m && y >= 1 && a[x][y] == '.' && !visited[x][y])
    return 1;
  return 0;
}
void dfs(int x, int y) {
  if (ctr >= s - k) return;
  visited[x][y] = 1;
  if (valid(x + 1, y)) {
    ctr++;
    dfs(x + 1, y);
    if (ctr >= s - k) return;
  }
  if (valid(x - 1, y)) {
    ctr++;
    dfs(x - 1, y);
    if (ctr >= s - k) return;
  }
  if (valid(x, y + 1)) {
    ctr++;
    dfs(x, y + 1);
    if (ctr >= s - k) return;
  }
  if (valid(x, y - 1)) {
    ctr++;
    dfs(x, y - 1);
    if (ctr >= s - k) return;
  }
  if (ctr >= s - k) return;
}
int main() {
  string str;
  int i, j;
  int f = 0;
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) {
    cin >> str;
    str = " " + str;
    for (j = 1; j <= m; j++) {
      a[i][j] = str[j];
      if (a[i][j] == '.') s++;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        dfs(i, j);
        f = 1;
        break;
      }
    }
    if (f) break;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '#')
        cout << a[i][j];
      else {
        if (visited[i][j])
          cout << ".";
        else
          cout << "X";
      }
    }
    cout << endl;
  }
  return 0;
}
