#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int dirx[] = {1, -1, 0, 0};
const int diry[] = {0, 0, 1, -1};
string grid[N];
bool vis[N][N];
int n, m, k;
bool valid(int x, int y) {
  return ((x < n and x >= 0) and (y < m and y >= 0) and grid[x][y] == '.' and
          !vis[x][y]);
}
void dfs(int x, int y) {
  if (!valid(x, y)) 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;
  int i, j;
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (grid[i][j] == '.') {
        break;
      }
    }
    if (j < m) break;
  }
  dfs(i, j);
  for (i = 0; i < n; i++) {
    cout << grid[i] << "\n";
  }
  return 0;
}
