#include <bits/stdc++.h>
using namespace std;
int n, m, k;
string s[502];
void dfs(int x, int y) {
  if (x >= n || x < 0 || y < 0 || y >= m || s[x][y] != '.' || k == 0) {
    return;
  }
  s[x][y] = '*';
  k--;
  dfs(x + 1, y);
  dfs(x, y + 1);
  dfs(x - 1, y);
  dfs(x, y - 1);
}
int main() {
  cin >> n >> m >> k;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cnt += (s[i][j] == '.');
    }
  }
  k = cnt - k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        dfs(i, j);
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '*') {
        cout << '.';
      } else if (s[i][j] == '.') {
        cout << 'X';
      } else {
        cout << s[i][j];
      }
    }
    cout << endl;
  }
  cout << endl;
  return 0;
}
