#include <bits/stdc++.h>
using namespace std;
char ma[501][501] = {0};
int vis[501][501] = {0}, n, m, k;
void dfs(int x, int y) {
  if (vis[x][y] || x < 0 || y < 0 || x > n || y > m || ma[x][y] != '.') return;
  vis[x][y] = 1;
  dfs(x - 1, y);
  dfs(x + 1, y);
  dfs(x, y - 1);
  dfs(x, y + 1);
  if (k) {
    ma[x][y] = 'X';
    k--;
  }
}
int main() {
  int a, b, c, d, e, f, g;
  scanf("%d%d%d%*c", &n, &m, &k);
  for (a = 0; a < n; a++) scanf("%s%*c", ma[a]);
  for (a = 0; a < n && k; a++)
    for (b = 0; b < m && k; b++) dfs(a, b);
  for (a = 0; a < n; a++) {
    if (a != 0) printf("\n");
    printf("%s", ma[a]);
  }
  return 0;
}
