#include <bits/stdc++.h>
using namespace std;
char arr[600][600];
int n, m, k, z = 0, c = 0;
bool visited[600][600] = {0};
void searching(int x, int y) {
  if (x == n || x < 0 || y == m || y < 0) return;
  if (!visited[x][y] && arr[x][y] == '.') {
    if (c == z) return;
    c++;
    visited[x][y] = 1;
  } else
    return;
  searching(x + 1, y);
  searching(x - 1, y);
  searching(x, y + 1);
  searching(x, y - 1);
}
int main() {
  int a, b;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == '.') z++, a = i, b = j;
    }
  z -= k;
  searching(a, b);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '.' && !visited[i][j])
        cout << "X";
      else
        cout << arr[i][j];
    }
    cout << endl;
  }
  return 0;
}
