#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char grid[501][501];
bool vis[501][501];
void dfs(int x, int y) {
  if (vis[x][y] || grid[x][y] != '.' || x < 0 || x >= n || y < 0 || y >= m)
    return;
  vis[x][y] = true;
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
  if (k) {
    grid[x][y] = 'X';
    k--;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> grid[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) dfs(i, j);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << grid[i][j];
    cout << "\n";
  }
  return 0;
}
