#include <bits/stdc++.h>
using namespace std;
char board[500][500];
int n, m, k;
int w = 0, e = 0;
int t;
bool used[500][500];
bool inBound(int a, int b) { return (a >= 0 && a < n && b >= 0 && b < m); }
bool dfs(int a, int b) {
  if (t == 0) return false;
  bool check = true;
  used[a][b] = true;
  for (int i = -1; i < 2; i++) {
    for (int j = -1; j < 2; j++) {
      if (abs(i) + abs(j) == 1 && inBound(a + i, b + j) &&
          board[a + i][b + j] == '.') {
        if (!used[a + i][b + j]) {
          check = dfs(a + i, b + j);
        }
      }
    }
  }
  if (t == 0) {
    return false;
  }
  if (check) {
    board[a][b] = 'X';
    t--;
  }
  return check;
}
int main() {
  for (int i = 0; i < 500; i++) {
    for (int j = 0; j < 500; j++) {
      used[i][j] = false;
    }
  }
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> board[i][j];
      if (board[i][j] == '.')
        e++;
      else
        w++;
    }
  }
  t = k;
  bool bla = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (board[i][j] == '.') {
        dfs(i, j);
        bla = true;
        break;
      }
    }
    if (bla) break;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << board[i][j];
    }
    cout << endl;
  }
  return 0;
}
