#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int mod = 7 + 1e9;
const int N = 503;
int n, m, k;
char s[N][N];
queue<pii> q;
int main() {
  cin >> n >> m >> k;
  int tot = 0, cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i] + 1;
    if (!k) continue;
    for (int j = 1; j <= m; ++j) {
      if (s[i][j] == '.') {
        s[i][j] = 'X';
        ++tot;
        if (q.empty()) {
          s[i][j] = '.';
          q.push({i, j});
          cnt = 1;
        }
      }
    }
  }
  while (q.size()) {
    pii x = q.front();
    q.pop();
    if (tot - cnt == k) break;
    for (int j = 0; j < 4; ++j) {
      int tx = dx[j] + x.first;
      int ty = dy[j] + x.second;
      if (tx && ty && s[tx][ty] == 'X') {
        q.push({tx, ty});
        s[tx][ty] = '.';
        ++cnt;
        if (tot - cnt == k) break;
      }
    }
  }
  for (int i = 1; i <= n; ++i) cout << s[i] + 1 << endl;
  return 0;
}
