#include <bits/stdc++.h>
using namespace std;
char s[505][505];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
int n, m, k;
int p = 0;
int q = 0;
void dfs(int x, int y, int depth, int ma) {
  s[x][y] = '.';
  p++;
  if (p == q) return;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i], yy = y + dy[i];
    if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
    if (s[xx][yy] != 'X') continue;
    if (p == q) return;
    dfs(xx, yy, depth + 1, ma);
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &k) > 0) {
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] == '.') {
          q++;
          s[i][j] = 'X';
        }
    q -= k;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (s[i][j] == 'X') {
          dfs(i, j, 0, q);
          for (int l = 0; l < n; l++) puts(s[l]);
          return 0;
        }
  }
}
