#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> fx = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pair<int, int>> fxx = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},
                              {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  char grid[n][m];
  int free = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
      if (grid[i][j] == '.') grid[i][j] = 'X', free++;
    }
  }
  k = free - k;
  queue<pair<int, int>> q;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (grid[i][j] == 'X') break;
    }
    if (j != m) break;
  }
  q.push({i, j});
  grid[i][j] = '.';
  k--;
  while (!q.empty()) {
    pair<int, int> s = q.front();
    q.pop();
    for (pair<int, int> t : fx) {
      t.first += s.first;
      t.second += s.second;
      if (!k || !(0 <= t.first && t.first < n) ||
          !(0 <= t.second && t.second < m) || grid[t.first][t.second] == '#' ||
          grid[t.first][t.second] == '.')
        continue;
      grid[t.first][t.second] = '.';
      q.push(t);
      k--;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << grid[i][j];
    }
    cout << '\n';
  }
}
