#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char maze[505][505];
bool vis[505][505];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
void dfs(int r, int c) {
  if (r >= n || r < 0 || c >= m || c < 0 || maze[r][c] == '#' || vis[r][c])
    return;
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) dfs(r + dx[i], c + dy[i]);
  if (k > 0) {
    maze[r][c] = 'X';
    k--;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  scanf("%d%d%d\n", &n, &m, &k);
  int x = -1, y = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &maze[i][j]);
      if (maze[i][j] == '.') {
        x = i, y = j;
      }
    }
    char c;
    scanf("%c", &c);
  }
  dfs(x, y);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%c", maze[i][j]);
    }
    printf("\n");
  }
}
