#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y;
char a[510][510];
bool b[510][510];
int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
void rec(int i, int j) {
  b[i][j] = 1;
  for (int g = 0; g < 4; g++) {
    if (a[i + xx[g]][j + yy[g]] == '.' && !b[i + xx[g]][j + yy[g]]) {
      rec(i + xx[g], j + yy[g]);
    }
  }
  if (k != 0) {
    k--;
    a[i][j] = 'X';
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        x = i;
        y = j;
      }
      b[i][j] = 0;
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    a[i][0] = '#';
    a[i][m + 1] = '#';
  }
  for (int j = 0; j <= m + 1; j++) {
    a[0][j] = '#';
    a[n + 1][j] = '#';
  }
  rec(x, y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
}
