#include <bits/stdc++.h>
using namespace std;
long mm = 1000000007;
const int maxn = 200005;
int n, m, k;
vector<string> s;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool isVisited[1000][1000] = {false};
void dfs(int x, int y) {
  if (!k || isVisited[x][y]) return;
  isVisited[x][y] = true;
  for (int kk = 0; kk < 4; kk++) {
    int a = x + dx[kk];
    int b = y + dy[kk];
    if (a < 0 || b < 0 || a >= n || b >= m || s[a][b] != '.') continue;
    dfs(a, b);
    isVisited[a][b] = true;
    if (!k) return;
  }
  s[x][y] = 'X';
  k--;
}
int main() {
  string ss;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> ss;
    s.push_back(ss);
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < m; i++) {
      if (s[j][i] != '.') {
        isVisited[j][i] = true;
        continue;
      }
      dfs(j, i);
    }
  }
  for (int i = 0; i < n; i++) cout << s[i] << endl;
  return 0;
}
