#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e9 + 9;
char maze[501][501];
bool vis[501][501];
int n, m, k, cnt, p;
bool valid(int r, int c) { return (r >= 0 && r < n && c >= 0 && c < m); }
void solve(int r, int c) {
  if (!valid(r, c) || maze[r][c] != '.' || vis[r][c] || cnt >= p) return;
  vis[r][c] = 1;
  cnt++;
  solve(r, c + 1);
  solve(r, c - 1);
  solve(r + 1, c);
  solve(r - 1, c);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> k;
  int x = -1, y = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> maze[i][j];
      if (maze[i][j] == '.' && x == -1) {
        x = i;
        y = j;
      }
      p += maze[i][j] == '.';
    }
  p -= k;
  solve(x, y);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (maze[i][j] == '.' && !vis[i][j]) maze[i][j] = 'X';
  for (int i = 0; i < n; ++i, cout << endl)
    for (int j = 0; j < m; ++j) cout << maze[i][j];
}
