#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 10;
const int MOD = (int)1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k, cnt = 0, can = 0;
  cin >> n >> m >> k;
  bool flag = true, visited[n + 2][m + 2], X[n + 2][m + 2];
  char arr[n + 2][m + 2];
  queue<pair<int, int>> q;
  memset(visited, false, sizeof(visited));
  memset(X, true, sizeof(X));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> arr[i][j], can += arr[i][j] == '.';
  for (int i = 1; i <= n && flag; i++)
    for (int j = 1; j <= m; j++)
      if (arr[i][j] == '.') {
        q.push(make_pair(i, j));
        flag = false;
        break;
      }
  while (q.size()) {
    int i = q.front().first, j = q.front().second;
    q.pop();
    if (visited[i][j]) continue;
    visited[i][j] = true;
    if (cnt == can - k) break;
    cnt++;
    X[i][j] = false;
    if (arr[i][j + 1] == '.') q.push(make_pair(i, j + 1));
    if (arr[i][j - 1] == '.') q.push(make_pair(i, j - 1));
    if (arr[i + 1][j] == '.') q.push(make_pair(i + 1, j));
    if (arr[i - 1][j] == '.') q.push(make_pair(i - 1, j));
  }
  for (int i = 1; i <= n; i++, cout << "\n")
    for (int j = 1; j <= m; j++)
      cout << (arr[i][j] == '#' ? '#' : X[i][j] ? 'X' : '.');
  return 0;
}
