#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modInverse(long long a, long long m = 1000000007) {
  if (m == 1) return 0;
  long long m0 = m, y = 0, x = 1;
  while (a > 1) {
    long long q = a / m, t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
vector<long long> par(3000), sizes(3000);
long long find_par(long long x) {
  if (x != par[x]) {
    return (par[x] = find_par(par[x]));
  }
  return x;
}
void union_set(long long a, long long b) {
  a = find_par(a), b = find_par(b);
  if (a != b) {
    if (sizes[a] < sizes[b]) {
      swap(a, b);
    }
    sizes[a] += sizes[b];
    par[b] = a;
  }
}
bool comp(vector<long long> v1, vector<long long> v2) {
  return v1.size() < v2.size();
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, w, h,
      count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,
      sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
  string s, s1, s2;
  cin >> n >> m >> k;
  char ar[n][m];
  vector<pair<long long, long long>> v;
  vector<vector<long long>> v1(n * m);
  for (i = 0; i <= n * m; i++) {
    par[i] = i;
    sizes[i] = 1;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> ar[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (ar[i][j] == '.') {
        p = i * m + j;
        if (i + 1 < n && ar[i + 1][j] == '.') {
          v1[p].push_back((i + 1) * m + j);
          v1[(i + 1) * m + j].push_back(p);
        }
        if (j + 1 < m && ar[i][j + 1] == '.') {
          v1[p].push_back(i * m + j + 1);
          v1[i * m + j + 1].push_back(p);
        }
      }
    }
  }
  for (i = 0; i < n * m; i++) {
    if (ar[i / m][i % m] == '.') {
      for (auto j : v1[i]) {
        union_set(i, j);
      }
    }
  }
  map<long long, long long> m1, m2;
  for (i = 0; i < n * m; i++) {
    if (ar[i / m][i % m] == '.') {
      x = find_par(i);
      if (i % m == 0 || (i + 1) % m == 0) {
        m2[x] = 1;
      } else if (i < m || i > (n - 1) * m) {
        m2[x] = 1;
      }
    }
  }
  for (i = 0; i < n * m; i++) {
    if (ar[i / m][i % m] == '.') {
      x = find_par(i);
      if (m2[x] == 0) {
        m1[x] = 1;
      }
    }
  }
  vector<vector<long long>> fa(n * m);
  for (i = 0; i < n * m; i++) {
    if (ar[i / m][i % m] == '.') {
      x = find_par(i);
      if (m1.count(x)) {
        fa[x].push_back(i);
      }
    }
  }
  for (i = 0; i < n * m; i++) {
    if (fa[i].size() != 0) {
      v.push_back({fa[i].size(), i});
    }
  }
  sort(v.begin(), v.end());
  x = v.size();
  i = 0;
  while (x > k) {
    ans += v[i].first;
    p = v[i].second;
    if (m1.count(p)) {
      for (auto j : fa[p]) {
        ar[j / m][j % m] = '*';
      }
    }
    i++;
    x--;
  }
  cout << ans << "\n";
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cout << ar[i][j];
    }
    cout << "\n";
  }
}
