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