#include <bits/stdc++.h>
using namespace std;
char a[1002][1002];
bool v[1002][1002];
int n, m, k;
void dfs(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m || a[x][y] != '.' || v[x][y]) return;
  v[x][y] = true;
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
  if (k) {
    a[x][y] = 'X';
    k--;
  }
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> (a[i] + 1);
  int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      if (a[i][j] == '.') break;
    if (j <= m) break;
  }
  dfs(i, j);
  for (int i = 1; i <= n; i++) cout << (a[i] + 1) << "\n";
}
