#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, num;
const int h[4] = {1, 0, -1, 0};
const int v[4] = {0, 1, 0, -1};
char maze[505][505];
int mark[505][505];
int nei(int x, int y) {
  int ans = 0;
  for (int i = 0; i < 4; i++)
    if (x + h[i] > -1 && x + h[i] < n && y + v[i] > -1 && y + v[i] < m)
      if (!mark[x + h[i]][y + v[i]]) ++ans;
  return ans;
}
void dfs(int x, int y) {
  if (num == s - k) return;
  ++num;
  mark[x][y] = 2;
  for (int i = 0; i < 4; i++)
    if (x + h[i] > -1 && x + h[i] < n && y + v[i] > -1 && y + v[i] < m)
      if (!mark[x + h[i]][y + v[i]]) dfs(x + h[i], y + v[i]);
}
int main() {
  int dx = 0, dy = 0;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> maze[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (maze[i][j] == '#') mark[i][j] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (maze[i][j] == '.') {
        dx = i;
        dy = j;
        ++s;
      }
  dfs(dx, dy);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mark[i][j] == 2)
        cout << '.';
      else if (mark[i][j] == 1)
        cout << '#';
      else
        cout << 'X';
    }
    cout << endl;
  }
  return 0;
}
