#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int INF = 1e9 + 7;
const long long int N = 507;
char ch[N][N];
bool vis[N][N];
long long int m, n, k, cnt;
long long int dir[][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
void dfs(long long int x, long long int y) {
  for (long long int i = 0; i < 4; i++) {
    long long int xx = x + dir[i][0];
    long long int yy = y + dir[i][1];
    if (xx >= 0 && xx < m && yy >= 0 && yy < n && ch[xx][yy] == '.' &&
        !vis[xx][yy] && cnt > 0) {
      cnt--;
      vis[xx][yy] = 1;
      dfs(xx, yy);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> m >> n >> k;
  long long int sx = -1, sy = -1;
  cnt = 0;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '.') {
        sx = i;
        sy = j;
        cnt++;
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  cnt -= k + 1;
  if (sx != -1 && sy != -1) {
    vis[sx][sy] = 1;
    dfs(sx, sy);
    for (long long int i = 0; i < m; i++) {
      for (long long int j = 0; j < n; j++) {
        if (ch[i][j] == '.' && !vis[i][j])
          cout << "X";
        else
          cout << ch[i][j];
      }
      cout << "\n";
    }
  } else {
    for (long long int i = 0; i < m; i++) {
      for (long long int j = 0; j < n; j++) {
        cout << ch[i][j];
      }
      cout << "\n";
    }
  }
  return 0;
}
