#include <bits/stdc++.h>
using namespace std;
char matrix[500][500];
int n, m, k, is, js;
int vis[500][500];
void DFS(int i, int j) {
  if (i < 0 || j < 0 || i == n || j == m || (matrix[i][j] == '#') ||
      vis[i][j]) {
    return;
  }
  vis[i][j] = 1;
  DFS(i - 1, j);
  DFS(i + 1, j);
  DFS(i, j - 1);
  DFS(i, j + 1);
  if (k > 0) {
    matrix[i][j] = 'X';
    k--;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix[i][j];
      if (matrix[i][j] == '.') {
        is = i;
        js = j;
      }
    }
  }
  DFS(is, js);
  for (int z = 0; z < n; z++) {
    for (int w = 0; w < m; w++) {
      cout << matrix[z][w];
    }
    cout << endl;
  }
}
