#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 5;
char ch[maxn][maxn];
int vis[maxn][maxn];
int n, m, p;
void dfs(int a, int b) {
  if (ch[a][b] == '#') return;
  if (vis[a][b] == 1) return;
  if (a < 0 || a >= n || b < 0 || b >= m) return;
  vis[a][b] = 1;
  dfs(a - 1, b);
  dfs(a + 1, b);
  dfs(a, b + 1);
  dfs(a, b - 1);
  if (p) {
    ch[a][b] = 'X';
    p--;
  }
}
int main() {
  memset(vis, 0, sizeof(vis));
  scanf("%d%d%d\n", &n, &m, &p);
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      scanf("%c", &ch[i][k]);
    }
    getchar();
  }
  while (p) {
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < m; k++) {
        dfs(i, k);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < m; k++) {
      printf("%c", ch[i][k]);
    }
    printf("\n");
  }
  return 0;
}
