#include <bits/stdc++.h>
using namespace std;
char ch[505][505];
int n, m, k, cnt, x, y, all, i, j, lol;
bool vis[505][505];
void dfs(int row, int col) {
  if (row < 0 || row >= n) return;
  if (col < 0 || col >= m) return;
  if (ch[row][col] == '#') return;
  if (cnt == all - k) return;
  if (vis[row][col]) return;
  cnt++;
  vis[row][col] = true;
  dfs(row + 1, col);
  dfs(row - 1, col);
  dfs(row, col + 1);
  dfs(row, col - 1);
}
int main() {
  cin >> n >> m >> k;
  memset(vis, false, sizeof vis);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '.') all++, x = i, y = j;
    }
  }
  dfs(x, y);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (ch[i][j] != '#' && !vis[i][j] && lol < k) ch[i][j] = 'X', lol++;
      if (lol == k) {
        i = n;
        break;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cout << ch[i][j];
    }
    cout << endl;
  }
}
