#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, k, m, s, num;
bool used[502][502];
char c[502][502];
void path(int x, int y) {
  if (num == k) return;
  num++;
  used[x][y] = true;
  if (!used[x + 1][y] and c[x + 1][y] == '.') path(x + 1, y);
  if (!used[x - 1][y] and c[x - 1][y] == '.') path(x - 1, y);
  if (!used[x][y + 1] and c[x][y + 1] == '.') path(x, y + 1);
  if (!used[x][y - 1] and c[x][y - 1] == '.') path(x, y - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int x, y;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '.') {
        s++;
        x = i;
        y = j;
      }
    }
  k = s - k;
  path(x, y);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!used[i][j] and c[i][j] == '.')
        cout << 'X';
      else
        cout << c[i][j];
    }
    cout << '\n';
  }
  return 0;
}
