#include <bits/stdc++.h>
using namespace std;
int x4[4] = {1, 0, 0, -1};
int y4[4] = {0, 1, -1, 0};
int n, m, k, y, vis[505][505], ans[505][505], c, t, h, sum;
char a[505][5005];
bool valid(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  return 1;
}
void dfs(int i, int j) {
  if (c == sum) return;
  vis[i][j] = 1;
  c++;
  ans[i][j] = t;
  for (int k = 0; k < 4; k++) {
    if (vis[i + x4[k]][j + y4[k]] == 0 && a[i + x4[k]][j + y4[k]] != '#' &&
        valid(i + x4[k], j + y4[k]))
      dfs(i + x4[k], j + y4[k]);
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') sum++;
    }
  }
  sum = n * m - sum - k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        c = 0;
        t++;
        dfs(i, j);
        if (c == sum) {
          h = 1;
          break;
        }
      }
    }
    if (h == 1) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ans[i][j] != t && a[i][j] != '#') a[i][j] = 'X';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}
