#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e2 + 20, mod = 998244353;
long long n, m, k, cnt, s;
bool b[MAXN][MAXN];
pair<long long, long long> tmp;
char a[MAXN][MAXN];
void Read_input() {
  cin >> n >> m >> k;
  memset(a, '#', sizeof(a));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        tmp = {i, j};
        s++;
      }
    }
  }
}
void dfs(long long x = tmp.first, long long y = tmp.second) {
  if (cnt == s - k) return;
  b[x][y] = true;
  cnt++;
  if (a[x + 1][y] == '.' and !b[x + 1][y]) dfs(x + 1, y);
  if (a[x - 1][y] == '.' and !b[x - 1][y]) dfs(x - 1, y);
  if (a[x][y + 1] == '.' and !b[x][y + 1]) dfs(x, y + 1);
  if (a[x][y - 1] == '.' and !b[x][y - 1]) dfs(x, y - 1);
}
void solve() {
  dfs();
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++)
      if (b[i][j] or a[i][j] == '#')
        cout << a[i][j];
      else
        cout << 'X';
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Read_input(), solve();
  return 0;
}
