#include <bits/stdc++.h>
using namespace std;
static bool sync_with_stdio(0);
bool Is2n(int n) {
  if (n <= 0) return false;
  if ((n & ((~n) + 1)) == n)
    return true;
  else
    return false;
}
int gcd(int a, int b) {
  int c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
struct Comparator {
  int operator()(const pair<int, int>& P1, const pair<int, int>& P2) const {
    return (P1.second > P2.second);
  }
};
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
vector<string> S;
vector<vector<int> > C;
int Y, X;
int Count = 1;
void DFS(int y, int x) {
  C[y][x] = Count++;
  for (int i = int(0); i < int(4); i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 0 && xx < X && yy >= 0 && yy < Y && C[yy][xx] == 0 &&
        S[yy][xx] == '.')
      DFS(yy, xx);
  }
}
int main() {
  int k;
  cin >> Y >> X >> k;
  C = vector<vector<int> >(Y);
  S = vector<string>(Y);
  vector<int> T(X, 0);
  for (int i = int(0); i < int(Y); i++) {
    cin >> S[i];
    C[i] = T;
  }
  bool R = true;
  for (int i = 0; i < Y && R; i++) {
    for (int j = 0; j < X && R; j++) {
      if (S[i][j] == '.') {
        DFS(i, j);
        R = false;
      }
    }
  }
  for (int i = int(0); i < int(Y); i++) {
    for (int j = int(0); j < int(X); j++) {
      if (S[i][j] == '.' && C[i][j] >= Count - k) S[i][j] = 'X';
    }
  }
  for (int i = int(0); i < int(Y); i++) cout << S[i] << endl;
  return 0;
}
