#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int ctr, s, n, m, k;
void dfsutil(vector<vector<char> > &arr, int x, int y,
             vector<vector<bool> > &vis) {
  if (x < 0 || x > arr.size() - 1 || y < 0 || y > arr[0].size() - 1 ||
      vis[x][y] || arr[x][y] == '#')
    return;
  vis[x][y] = true;
  dfsutil(arr, x + 1, y, vis);
  dfsutil(arr, x - 1, y, vis);
  dfsutil(arr, x, y + 1, vis);
  dfsutil(arr, x, y - 1, vis);
  if (k) {
    arr[x][y] = 'X';
    k--;
  }
}
void dfs(vector<vector<char> > &arr, int x, int y, vector<vector<bool> > &vis) {
  dfsutil(arr, x, y, vis);
}
int main() {
  cin >> n >> m >> k;
  int x, y;
  vector<vector<char> > maze(n, vector<char>(m));
  bool check = false;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == '.' && check == false) x = i, y = j, check = true;
    }
  }
  if (k == 0) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << maze[i][j];
      cout << endl;
    }
    return 0;
  }
  vector<vector<bool> > vis(n, vector<bool>(m, false));
  dfs(maze, x, y, vis);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << maze[i][j];
    cout << endl;
  }
}
