#include <bits/stdc++.h>
using namespace std;
vector<long long> prime(1000005, 1);
void cal_primearray(long long n) {
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == 1) {
      for (int i = p * 2; i <= n; i += p) prime[i] = 0;
    }
  }
}
long long modexpo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long expo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  }
  return true;
}
long long max_value(vector<long long> arr) {
  long long m = 0;
  for (int i = 0; i < arr.size(); i++) m = max(m, arr[i]);
  return m;
}
void kmp(string second) {
  vector<long long> v(second.length() + 1, 0);
  long long cur = 0;
  for (int j = 2; j < second.length(); j++) {
    while (cur != 0 && second[cur] != second[j - 1]) cur = v[cur];
    if (second[cur] == second[j - 1]) cur++;
    v[j] = cur;
  }
}
long long nCr(long long n, long long k) {
  if (k == 0) return 1;
  return (n * nCr(n - 1, k - 1)) / k;
}
int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};
bool myfunc(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second < b.second;
  return (a.first < b.first);
}
vector<string> foo;
set<pair<int, int> > bar;
int vis[500 + 1][500 + 1];
long long k;
bool check(int a, int b, int n, int m) {
  return a < n && a >= 0 && b >= 0 && b < m && (foo[a][b] != '#');
}
void dfs(int x, int y, int n, int m) {
  vis[x][y] = 1;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      if ((abs(i) != abs(j)) && !vis[x + i][y + j] &&
          check(x + i, y + j, n, m) && k) {
        bar.insert(make_pair(x + i, y + j));
        k--;
        dfs(x + i, y + j, n, m);
      }
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    foo.push_back(temp);
  }
  pair<int, int> free;
  int flag = 0;
  int coun = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (foo[i][j] == '#')
        continue;
      else {
        coun++;
        if (flag != 1) free = make_pair(i, j);
        flag = 1;
      }
    }
  }
  bar.insert(make_pair(free.first, free.second));
  k = coun - k - 1;
  dfs(free.first, free.second, n, m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (foo[i][j] == '#')
        continue;
      else if (bar.find(make_pair(i, j)) == bar.end())
        foo[i][j] = 'X';
    }
  }
  for (int i = 0; i < n; i++) cout << foo[i] << "\n";
  return 0;
}
