#include <bits/stdc++.h>
using namespace std;
string s[505];
int n, m, k;
bool vi[505][505];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void dfs(int x, int y) {
  bool f = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx < n && xx >= 0 && yy < m && yy >= 0 && s[xx][yy] == '.' &&
        !vi[xx][yy]) {
      vi[xx][yy] = 1;
      dfs(xx, yy);
    }
  }
  if (k) {
    s[x][y] = 'X';
    k--;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        dfs(i, j);
        break;
        break;
      }
    }
  for (int i = 0; i < n; i++) cout << s[i] << endl;
  return 0;
}
