#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long powe(long long x, long long y) {
  x = x % mod, y = y % (mod - 1);
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
void fun() {}
long long m, n, k;
char a[505][505];
bool visited[505][505];
void dfs(long long i, long long j) {
  visited[i][j] = true;
  if (i > 0 and a[i - 1][j] == '.' and !visited[i - 1][j]) dfs(i - 1, j);
  if (j > 0 and a[i][j - 1] == '.' and !visited[i][j - 1]) dfs(i, j - 1);
  if (i < m - 1 and a[i + 1][j] == '.' and !visited[i + 1][j]) dfs(i + 1, j);
  if (j < n - 1 and a[i][j + 1] == '.' and !visited[i][j + 1]) dfs(i, j + 1);
  if (k) {
    a[i][j] = 'X';
    k--;
  }
}
signed main() {
  fun();
  long long t = 1;
  while (t--) {
    cin >> m >> n >> k;
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < n; j++) {
        if (k and a[i][j] == '.' and !visited[i][j]) dfs(i, j);
      }
    }
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < n; j++) {
        cout << a[i][j];
      }
      cout << "\n";
    }
  }
  return 0;
}
