#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
char maze[501][501];
int n, m, k;
int vis[501][501];
bool valid(int r, int c) {
  return r >= 0 && r < n && c >= 0 && c < m && maze[r][c] == '.';
}
void dfs(int r, int c) {
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) {
    int nr = r + dy[i], nc = c + dx[i];
    if (valid(nr, nc) && !vis[nr][nc]) dfs(nr, nc);
  }
  if (k) maze[r][c] = 'X', k--;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) scanf("%s", maze[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (!vis[i][j] && maze[i][j] == '.') dfs(i, j);
  for (int i = 0; i < n; i++) printf("%s\n", maze[i]);
  return 0;
}
