#include <bits/stdc++.h>
using namespace std;
char adjlist[600][600];
bool visit[600][600];
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
int m, n, k;
void dfs(int i, int j) {
  if (adjlist[i][j] != '.' || visit[i][j] == true) return;
  visit[i][j] = true;
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
  if (k == 0) {
    for (int z = 1; z <= n; z++) {
      for (int w = 1; w <= m; w++) cout << adjlist[z][w];
      cout << "\n";
    }
    exit(0);
  }
  adjlist[i][j] = 'X';
  k--;
}
void floodfill(int r, int c, char c1, char c2) {
  if (adjlist[r][c] != c1 || visit[r][c] == true || r < 0 || r > n || c < 0 ||
      c > m)
    return;
  visit[r][c] = true;
  for (int d = 0; d < 4; d++) floodfill(r + dr[d], c + dc[d], c1, c2);
  if (k == 0) {
    for (int z = 1; z <= n; z++) {
      for (int w = 1; w <= m; w++) cout << adjlist[z][w];
      cout << "\n";
    }
    exit(0);
  }
  adjlist[r][c] = c2;
  k--;
}
int main() {
  memset(visit, false, sizeof visit);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> adjlist[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (adjlist[i][j] == '.') dfs(i, j);
  return 0;
}
