#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e2 + 5;
const int mod = 1e9 + 7;
const int INF = 1e9;
int n, m, k, sx, sy;
string mat[mxN];
bool vis[mxN][mxN];
bool notvalid(int i, int j) {
  return (i < 0 || j < 0 || i >= n || j >= m || mat[i][j] != '.' || vis[i][j]);
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void dfs(int i, int j) {
  if (notvalid(i, j)) return;
  int x, y;
  vis[i][j] = true;
  for (int v = 0; v < 4; v++) {
    x = i + dx[v];
    y = j + dy[v];
    if (notvalid) {
      dfs(x, y);
    }
  }
  if (k > 0) {
    mat[i][j] = 'X';
    k--;
  }
  return;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '.') {
        sx = i;
        sy = j;
      }
      vis[i][j] = false;
    }
  }
  dfs(sx, sy);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << mat[i][j];
    }
    cout << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(12) << fixed;
  solve();
  return 0;
}
