#include <bits/stdc++.h>
using namespace std;
char mp[511][511];
int n, m, k, tot;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
void dfs(int x, int y) {
  mp[x][y] = '.';
  --tot;
  for (int i(0); tot && i < 4; ++i)
    if (mp[x + dx[i]][y + dy[i]] == 'X') dfs(x + dx[i], y + dy[i]);
}
int main() {
  int i, j;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 0; i <= m + 1; ++i) mp[0][i] = mp[n + 1][i] = '#';
  for (i = 0; i <= n + 1; ++i) mp[i][0] = mp[i][m + 1] = '#';
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      scanf(" %c", &mp[i][j]);
      if (mp[i][j] == '.') {
        ++tot;
        mp[i][j] = 'X';
      }
    }
  tot -= k;
  for (i = 1; tot && i <= n; ++i)
    for (j = 1; tot && j <= m; ++j)
      if (mp[i][j] == 'X') dfs(i, j);
  for (i = 1; i <= n; ++i, printf("\n"))
    for (j = 1; j <= m; ++j) printf("%c", mp[i][j]);
  return 0;
}
