#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int n, m, k;
char mp[maxn][maxn];
int x, y, vis[maxn][maxn];
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || vis[x][y] || mp[x][y] == '#')
    return;
  vis[x][y] = 1;
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
  if (k) mp[x][y] = 'X', k--;
}
int main() {
  while (~scanf("%d%d%d", &n, &m, &k)) {
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < n; ++i) {
      scanf("%s", mp + i);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (mp[i][j] == '.') {
          x = i;
          y = j;
        }
      }
    }
    dfs(x, y);
    for (int i = 0; i < n; ++i) printf("%s\n", mp + i);
  }
  return 0;
}
