#include <bits/stdc++.h>
using namespace std;
const int N = 505;
char data[N][N];
char visited[N][N];
int n, m, k;
void dfs(int x, int y) {
  if (k == 0) return;
  if (data[x][y] != '.') return;
  if (visited[x + 1][y + 1]) return;
  visited[x + 1][y + 1] = 1;
  dfs(x - 1, y);
  dfs(x + 1, y);
  dfs(x, y - 1);
  dfs(x, y + 1);
  if (k) {
    k--;
    data[x][y] = 'X';
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    scanf("%s", data[i]);
  }
  if (k) {
    for (int i = 0; i <= n + 1; i++) {
      visited[i][0] = visited[i][m + 1] = 1;
    }
    for (int i = 0; i <= m + 1; i++) {
      visited[0][i] = visited[n + 1][i] = 1;
    }
    bool is_continue = 1;
    for (int i = 0; i < n && is_continue; i++)
      for (int j = 0; j < m; j++)
        if (data[i][j] == '.') {
          dfs(i, j);
          is_continue = 0;
          break;
        }
  }
  for (int i = 0; i < n; i++) {
    printf("%s\n", data[i]);
  }
  return 0;
}
