#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void dfs(vector<string> &s, int x, int y, int &tot) {
  if (!tot) return;
  if (s[x][y] == 'X' || s[x][y] == '#') return;
  s[x][y] = 'X';
  tot--;
  if (x > 0) dfs(s, x - 1, y, tot);
  if (x < s.size() - 1) dfs(s, x + 1, y, tot);
  if (y > 0) dfs(s, x, y - 1, tot);
  if (y < s[0].size() - 1) dfs(s, x, y + 1, tot);
}
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<string> s(n);
  for (string &i : s) cin >> i;
  int cnt = 0;
  for (string &i : s) {
    cnt += count(i.begin(), i.end(), '.');
  }
  cnt -= k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        dfs(s, i, j, cnt);
        break;
      }
    }
  }
  for (string &i : s) {
    for (char &c : i) {
      if (c == '.')
        c = 'X';
      else if (c == 'X')
        c = '.';
      cout << c;
    }
    cout << '\n';
  }
}
int main() {
  int t = 1;
  while (t--) solve(), cout << '\n';
}
