#include <bits/stdc++.h>
using namespace std;
const int N = 500;
bool vis[N][N];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
long long c, n, m, res;
char arr[N][N];
bool valid(long long i, long long j) {
  return (i >= 0 && j >= 0 && i < n && j < m && !vis[i][j] &&
          arr[i][j] == 'X' && c < res);
}
void dfs(long long i, long long j) {
  if (!valid(i, j)) return;
  c++;
  arr[i][j] = '.';
  vis[i][j] = 1;
  for (long long x = 0; x < 4; x++) dfs(i + dx[x], j + dy[x]);
}
int main() {
  long long k, x, y, counter = 0;
  cin >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '.') {
        x = i, y = j;
        arr[i][j] = 'X';
        counter++;
      }
    }
  }
  res = counter - k;
  dfs(x, y);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cout << arr[i][j];
    cout << endl;
  }
  return 0;
}
