#include <bits/stdc++.h>
using namespace std;
char g[501][501];
bool vis[501][501];
int n, m, k;
int a[] = {0, 0, 1, -1};
int b[] = {1, -1, 0, 0};
bool can(int x, int y) {
  return x >= 0 && y >= 0 && x < n && y < m && g[x][y] != '#' && !vis[x][y];
}
void flood(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++)
    if (can(x + a[i], y + b[i])) flood(x + a[i], y + b[i]);
  if (k) {
    g[x][y] = 'X';
    k--;
  }
}
int main() {
  int x, y;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
      if (g[i][j] != '#') x = i, y = j;
    }
  flood(x, y);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << g[i][j];
    cout << endl;
  }
}
