#include <bits/stdc++.h>
using namespace std;
char c[505][505];
int vis[505][505];
int n, m, k, tc, ct;
bool asser(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && c[i][j] == '.' && (!vis[i][j]))
    return true;
  else
    return false;
}
void dfs(int i, int j) {
  if (tc - ct <= k) return;
  vis[i][j] == 1;
  ct++;
  c[i][j] = 'm';
  if (asser(i - 1, j)) dfs(i - 1, j);
  if (asser(i + 1, j)) dfs(i + 1, j);
  if (asser(i, j - 1)) dfs(i, j - 1);
  if (asser(i, j + 1)) dfs(i, j + 1);
}
int main() {
  cin >> n >> m >> k;
  tc = 0;
  ct = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '.') tc++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == '.') dfs(i, j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (c[i][j] == 'm')
        cout << ".";
      else if (c[i][j] == '.')
        cout << "X";
      else
        cout << "#";
    }
    cout << "\n";
  }
  return 0;
}
