#include <bits/stdc++.h>
using namespace std;
int n, m;
bool visited[500][500];
char a[500][500];
int movex[] = {0, 1, 0, -1};
int movey[] = {1, 0, -1, 0};
int k1;
bool valid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && a[i][j] == '.' &&
         visited[i][j] == 0;
}
void dfs(int i, int j) {
  visited[i][j] = 1;
  if (k1 <= 0) return;
  for (int k = 0; k < 4; k++) {
    if (valid(i + movex[k], j + movey[k])) {
      dfs(i + movex[k], j + movey[k]);
    }
  }
  if (k1 > 0) a[i][j] = 'X', k1--;
}
int main() {
  cin >> n >> m >> k1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      visited[i][j] = 0;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!visited[i][j] && a[i][j] == '.') dfs(i, j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << a[i][j];
    cout << endl;
  }
}
