#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int>pi;
typedef pair<ll, ll>pl;
typedef vector<pi>vpi;
typedef vector<pl>vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
const long double PI = acos(-1);
const ll oo = LLONG_MAX;
const int MOD = 1e9 + 7;
const int N = 5e2 + 7;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define read(v) for (auto& it : v) scanf("%d", &it);
#define readl(v) for (auto& it : v) scanf("%lld", &it);
#define print(v) for (auto it : v) printf("%d ", it); puts("");
#define printl(v) for (auto it : v) printf("%lld ", it); puts("");
int n, m, k;
vector<string>v(N);
vector<vector<bool>>vis(N, vector<bool>(N));
int dr[] = { 0,0,-1,1 }, dc[] = { -1,1,0,0 };
void DFS(int r, int c) {
vis[r][c] = true;
for (int i = 0; i < 4; i++) {
int nr = r + dr[i], nc = c + dc[i];
if (nr < 0 || nr >= n || nc < 0 || nc >= m || v[nr][nc] == '#' || v[nr][nc] == 'X' || vis[nr][nc])
continue;
DFS(nr, nc);
}
if (k)
v[r][c] = 'X', k--;
}
void init() {
for (int i = 0; i <= n; i++) {
v[i].clear();
for (int j = 0; j <= m; j++)
vis[i][j] = false;
}
}
void solve() {
scanf("%d %d %d", &n, &m, &k);
init();
for (auto& it : v) {
char c[500];
scanf("%s", &c);
it = c;
}
for (int i = 0; i < n; i++) {
bool oki = false;
for (int j = 0; j < m; j++) {
if (v[i][j] == '.') {
DFS(i, j);
oki = true;
break;
}
}
if (oki)
break;
}
for (int i = 0; i < n; i++)
puts(v[i].c_str());
}
int t = 1;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//scanf("%d", &t);
while (t--) solve();
}
77u/I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwoja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