#include <bits/stdc++.h>
using namespace std;
long long int arr[501][501];
vector<long long int> v[250002];
bool vst[250002] = {false};
void dfs(long long int h, long long int s, long long int k,
         long long int &count) {
  if (count < s - k) {
    queue<long long int> q;
    q.push(h);
    vst[h] = true;
    count++;
    while (!q.empty()) {
      long long int p = q.front();
      q.pop();
      for (long long int i = 0; i < v[p].size(); i++) {
        if (!vst[v[p][i]]) {
          dfs(v[p][i], s, k, count);
        }
      }
    }
  } else {
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, k;
  cin >> n >> m >> k;
  long long int s = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        arr[i][j] = s;
        s++;
      } else {
        arr[i][j] = -1;
      }
    }
  }
  long long int h = s - 1;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (arr[i][j] != -1) {
        if ((i - 1 > 0) && arr[i - 1][j] != -1) {
          v[arr[i][j]].push_back(arr[i - 1][j]);
        }
        if ((j - 1 > 0) && arr[i][j - 1] != -1) {
          v[arr[i][j]].push_back(arr[i][j - 1]);
        }
        if (i + 1 <= n && arr[i + 1][j] != -1) {
          v[arr[i][j]].push_back(arr[i + 1][j]);
        }
        if (j + 1 <= m && arr[i][j + 1] != -1) {
          v[arr[i][j]].push_back(arr[i][j + 1]);
        }
      }
    }
  }
  long long int count = 0;
  dfs(h, s, k, count);
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (arr[i][j] == -1) {
        cout << '#';
      } else if (vst[arr[i][j]] == true) {
        cout << '.';
      } else {
        cout << 'X';
      }
    }
    cout << "\n";
  }
}
