#include <bits/stdc++.h>
using namespace std;
int n, m, k, c;
int movex[] = {1, -1, 0, 0}, movey[] = {0, 0, 1, -1};
string s[501];
int vis[501][501];
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || vis[x][y] == 1 || s[x][y] == '#')
    return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    dfs(x + movex[i], y + movey[i]);
  }
  if (c < k) {
    s[x][y] = 'X';
    c++;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dfs(i, j);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << s[i] << '\n';
  }
}
