#include <bits/stdc++.h>
using namespace std;
int row[] = {-1, 0, 0, 1};
int col[] = {0, -1, 1, 0};
int n, m, k;
char matrix[501][501];
bool visited[501][501] = {0};
bool isValid(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) return true;
  return false;
}
void dfs(int i, int j) {
  visited[i][j] = 1;
  for (int x = 0; x < 4; x++) {
    int new_i = i + row[x];
    int new_j = j + col[x];
    if (isValid(new_i, new_j) && !visited[new_i][new_j] &&
        matrix[new_i][new_j] == '.')
      dfs(new_i, new_j);
  }
  if (k == 0)
    return;
  else {
    matrix[i][j] = 'X';
    k--;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  bool flag = true;
  int start_i, start_j;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix[i][j];
      if (flag && matrix[i][j] == '.') {
        start_i = i;
        start_j = j;
        flag = false;
      }
    }
  }
  dfs(start_i, start_j);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << matrix[i][j];
    }
    cout << "\n";
  }
}
