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