#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char a[505][505];
int deg[505][505];
bool ok(int x, int y) {
  if (x < 0 or y < 0 or x >= n or y >= m or a[x][y] == '#' or a[x][y] == 'X')
    return false;
  return true;
}
int seen[505][505];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int cnt;
int s;
void dfs(int x, int y) {
  if (cnt == (s - k)) return;
  cnt++;
  seen[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (ok(nx, ny) and seen[nx][ny] == 0) {
      dfs(nx, ny);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  int x, y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        s++;
        x = i;
        y = j;
      }
    }
  dfs(x, y);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (seen[i][j] == 0 and a[i][j] == '.')
        cout << "X";
      else
        cout << a[i][j];
    }
    cout << '\n';
  }
  return 0;
}
