#include <bits/stdc++.h>
using namespace std;
bool used[510][510];
char maps[510][510];
int n, m;
int deep;
struct node {
  int x, y;
  node() {}
  node(int _x, int _y) {
    x = _x;
    y = _y;
  }
} s;
bool judge(node a) {
  return a.x >= 0 && a.x < n && a.y >= 0 && a.y < m && maps[a.x][a.y] != '#';
}
int xx[] = {-1, 0, 0, 1};
int yy[] = {0, -1, 1, 0};
bool bfs(int num) {
  queue<node> q;
  q.push(s);
  used[s.x][s.y] = true;
  deep++;
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    if (num == deep) return true;
    for (int i = 0; i < 4; ++i) {
      node next = node(now.x + xx[i], now.y + yy[i]);
      if (judge(next) && !used[next.x][next.y]) {
        used[next.x][next.y] = true;
        deep++;
        if (deep == num) return true;
        q.push(next);
      }
    }
  }
  return false;
}
int main() {
  int k = 0;
  char ch[10];
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    gets(ch);
    memset(maps, 0, sizeof(maps));
    for (int i = 0; i < n; ++i) gets(maps[i]);
    int cnt = 0;
    int f = false;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (maps[i][j] == '.') {
          cnt++;
          s.x = i;
          s.y = j;
        }
      }
    }
    memset(used, 0, sizeof(used));
    deep = 0;
    f = bfs(cnt - k);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (used[i][j] == false && maps[i][j] == '.') maps[i][j] = 'X';
      }
    }
    for (int i = 0; i < n; ++i) cout << maps[i] << endl;
  }
}
