#include <bits/stdc++.h>
using namespace std;
const int M = 1e6, N = 1000, MOD = 1e9 + 7, OO = 1e16;
int m, n, k, vis[N][N], bla, c, cnt, ans, sum, b[N], ok;
pair<int, int> p;
vector<int> v;
set<long long> ss;
string a[N], t;
map<int, int> mp;
vector<vector<int> > G;
int x[] = {0, 0, -1, 1};
int y[] = {-1, 1, 0, 0};
bool check(int i, int j) {
  return (i >= 0 && i < n && j < m && j >= 0 && a[i][j] != '#' && !vis[i][j]);
}
void DFS(int i, int j) {
  if (sum - k == c) return;
  vis[i][j] = 1;
  for (int w = 0; w < 4; w++) {
    int xx = i + x[w];
    int yy = j + y[w];
    if (check(xx, yy) && sum - k > c) {
      c++;
      DFS(xx, yy);
    }
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        if (!ok) p = {i, j};
        sum++;
        ok = 1;
      }
    }
  }
  DFS(p.first, p.second);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && a[i][j] == '.') a[i][j] = 'X';
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
  return 0;
}
