#include <bits/stdc++.h>
using namespace std;
bool w[505][505];
char q[505][505];
int a, s, d;
void dfs(int i, int j) {
  if (i <= 0 || j <= 0 || i > a || j > s || q[i][j] != '.' || w[i][j] == 1 ||
      d < 1)
    return;
  w[i][j] = 1;
  dfs(i, j + 1);
  dfs(i, j - 1);
  dfs(i - 1, j);
  dfs(i + 1, j);
  if (d > 0) q[i][j] = 'X', d--;
}
int main() {
  cin >> a >> s >> d;
  for (int i = 1; i <= a; i++)
    for (int j = 1; j <= s; j++) {
      cin >> q[i][j];
      if (q[i][j] == '#') w[i][j] = 1;
    }
  for (int i = 1; i <= a; i++)
    for (int j = 1; j <= s; j++)
      if (w[i][j] == 0) dfs(i, j);
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= s; j++) cout << q[i][j];
    cout << endl;
  }
}
