#include <bits/stdc++.h>
using namespace std;
const int N = int(300000) + 5;
template <typename T, typename T1>
void prin(vector<pair<T, T1> >& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].fi << " " << a[i].se << "\n";
  }
}
template <typename T>
void prin_new_line(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << "\n";
  }
}
template <typename T, typename T1>
void prin_new_line(vector<pair<T, T1> >& a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].fi << " " << a[i].se << "\n";
  }
}
int sum_vec(vector<int>& a) {
  int s = 0;
  for (int i = 0; i < a.size(); i++) {
    s += a[i];
  }
  return s;
}
template <typename T>
T max(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = max(ans, a[i]);
  }
  return ans;
}
template <typename T>
T min(vector<T>& a) {
  T ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    ans = min(ans, a[i]);
  }
  return ans;
}
template <typename T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
long double s_triangle(long double x1, long double y1, long double x2,
                       long double y2, long double x3, long double y3) {
  return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2);
}
bool overflow(long long int a, long long int b) {
  if (a * b / b != a) return true;
  return false;
}
long long int n, m, k, p, q, x1, y3, x2, y2, x, y, sum = 0, r, cnt, cnt1;
long long int a[N], b[60][60];
string s[60];
void solve2(long long int i, long long int j) {
  if (i >= n)
    return;
  else if (j >= m)
    return;
  else if (j < 0)
    return;
  else if (i < 0)
    return;
  else if (s[i][j] == 'Y') {
    cnt1++;
    s[i][j] = '*';
    solve2(i + 1, j);
    solve2(i, j + 1);
    solve2(i - 1, j);
    solve2(i, j - 1);
  } else
    return;
}
void solve1(long long int i, long long int j) {
  if (i >= n)
    return;
  else if (j >= m)
    return;
  else if (j < 0)
    return;
  else if (i < 0)
    return;
  else if (s[i][j] == '.') {
    cnt1++;
    s[i][j] = 'Y';
    solve1(i + 1, j);
    solve1(i, j + 1);
    solve1(i - 1, j);
    solve1(i, j - 1);
  } else
    return;
}
void solve(long long int i, long long int j) {
  if (i >= n)
    return;
  else if (j >= m)
    return;
  else if (j < 0)
    return;
  else if (i < 0)
    return;
  else if (s[i][j] == '.') {
    s[i][j] = 'N';
    solve(i + 1, j);
    solve(i, j + 1);
    solve(i - 1, j);
    solve(i, j - 1);
  } else
    return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (long long int i = 0; i <= n - 1; i++) cin >> s[i];
  for (long long int i = 0; i <= n - 1; i++) {
    for (long long int j = 0; j <= m - 1; j++) {
      if (i == 0 or j == 0 or j == m - 1 or i == n - 1) {
        if (s[i][j] == '.') solve(i, j);
      }
    }
  }
  p = 0;
  for (long long int i = 0; i <= n - 1; i++) {
    for (long long int j = 0; j <= m - 1; j++) {
      if (s[i][j] == '.') {
        cnt1 = 0;
        cnt++;
        solve1(i, j);
        a[p] = cnt1;
        p++;
        b[i][j] = cnt1;
      }
    }
  }
  sort(a, a + p);
  r = 0;
  long long int f = 0;
  for (long long int x = 0; x <= cnt - k - 1; x++) {
    f = 0;
    for (long long int i = 0; i <= n - 1; i++) {
      for (long long int j = 0; j <= m - 1; j++) {
        if (b[i][j] == a[x] and s[i][j] == 'Y') {
          cnt1 = 0;
          solve2(i, j);
          r += cnt1;
          f = 1;
          b[i][j] = -1;
          break;
        }
      }
      if (f) break;
    }
  }
  cout << r << endl;
  for (long long int i = 0; i <= n - 1; i++) {
    for (long long int j = 0; j <= m - 1; j++) {
      if (s[i][j] == 'N' or s[i][j] == 'Y')
        cout << '.';
      else
        cout << s[i][j];
    }
    cout << endl;
  }
  return 0;
}
