#include <bits/stdc++.h>
using namespace std;
int dr[] = {1, 0, -1, 0};
int dc[] = {0, 1, 0, -1};
int n, m, k, x, y, e = 0, ct = 0;
vector<string> v(n);
vector<vector<bool>> vis;
void bfs(int a, int b) {
  queue<pair<int, int>> q;
  q.push(make_pair(a, b));
  vis[a][b] = 1;
  e--;
  while (e >= 0 && !q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nr = dr[i] + t.first;
      int nc = dc[i] + t.second;
      if (nr < 0 || nr >= n || nc < 0 || nc >= m || v[nr][nc] == '#' ||
          vis[nr][nc])
        continue;
      if (e <= 0) break;
      vis[nr][nc] = true;
      e--;
      q.push(make_pair(nr, nc));
    }
  }
}
int main() {
  cin >> n >> m >> k;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    for (int j = 0; j < m; j++)
      if (v[i][j] == '.') {
        x = i;
        y = j;
        e++;
      }
  }
  vis.resize(n, vector<bool>(m, false));
  e -= k;
  bfs(x, y);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == '.' && !vis[i][j])
        cout << "X";
      else
        cout << v[i][j];
    }
    cout << endl;
  }
}
