#include <bits/stdc++.h>
using namespace std;
char field[500][501];
int isVisit[500][500];
int n, m, K;
const int mov[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main(void) {
  scanf("%d %d %d", &n, &m, &K);
  int empty = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", field[i]);
    for (int j = 0; j < m; j++)
      if (field[i][j] == '.') empty++;
  }
  queue<pair<int, int> > q;
  for (int i = 0; i < n && q.size() == 0; i++)
    for (int j = 0; j < m && q.size() == 0; j++)
      if (field[i][j] == '.') {
        isVisit[i][j] = true;
        q.push(make_pair(i, j));
      }
  int cnt = 1;
  while (!q.empty() && cnt < empty - K) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int i = 0; i < 4 && cnt < empty - K; i++) {
      int ny = y + mov[i][0];
      int nx = x + mov[i][1];
      if (ny >= 0 && ny < n && nx >= 0 && nx < m && isVisit[ny][nx] == false &&
          field[ny][nx] == '.') {
        isVisit[ny][nx] = true;
        q.push(make_pair(ny, nx));
        cnt++;
      }
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (field[i][j] == '.' && !isVisit[i][j]) field[i][j] = 'X';
  for (int i = 0; i < n; i++) printf("%s\n", field[i]);
  return 0;
}
