#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  string in[n];
  for (int i = 0; i < n; i++) cin >> in[i];
  int ans = 0, cnt = 0;
  int x, y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (in[i][j] == '.') {
        x = j;
        y = i;
        in[i][j] = 'X';
        cnt++;
      }
    }
  }
  bool used[n][m];
  memset(used, 0, sizeof used);
  queue<int> xs, ys;
  xs.push(x);
  ys.push(y);
  while (cnt > k) {
    x = xs.front();
    y = ys.front();
    used[y][x] = true;
    xs.pop();
    ys.pop();
    cnt--;
    in[y][x] = '.';
    for (int k = 0; k < 4; k++) {
      int nx = x + dx[k], ny = y + dy[k];
      if (0 <= nx && nx < m && 0 <= ny && ny < n && in[ny][nx] == 'X' &&
          !used[ny][nx]) {
        xs.push(nx);
        ys.push(ny);
        used[ny][nx] = true;
      }
    }
  }
  for (int i = 0; i < n; i++) cout << in[i] << endl;
  return 0;
}
