#include <iostream>
using namespace std;
const int N = 505;
char color[N][N];
int pre_p[N][N], pre_g[N][N], pre_b[N][N];
int calc_P(int x1, int y1, int x2, int y2) {
return pre_p[x2][y2] - pre_p[x2][y1 - 1] - pre_p[x1 - 1][y2] + pre_p[x1 - 1][y1 - 1];
}
int calc_G(int x1, int y1, int x2, int y2) {
return pre_g[x2][y2] - pre_g[x2][y1 - 1] - pre_g[x1 - 1][y2] + pre_g[x1 - 1][y1 - 1];
}
int calc_B(int x1, int y1, int x2, int y2) {
return pre_b[x2][y2] - pre_b[x2][y1 - 1] - pre_b[x1 - 1][y2] + pre_b[x1 - 1][y1 - 1];
}
int check1(int x1, int y1, int x2, int y2, int k) {
if (calc_P(x1, y1, x2, y2) > 0) {
return 0;
}
if (calc_G(x1, y1, x2, y2) <= k) {
return 1;
}
if (calc_B(x1, y1, x2, y2) <= k) {
return 2;
}
return 0;
}
bool check2(int x1, int y1, int x2, int y2) {
return calc_P(x1, y1, x2, y2) == (x2 - x1 + 1) * (y2 - y1 + 1);
}
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> color[i][j];
pre_p[i][j] = pre_p[i - 1][j] + pre_p[i][j - 1] - pre_p[i - 1][j - 1] + (color[i][j] == 'P' ? 1 : 0);
pre_g[i][j] = pre_g[i - 1][j] + pre_g[i][j - 1] - pre_g[i - 1][j - 1] + (color[i][j] == 'G' ? 1 : 0);
pre_b[i][j] = pre_b[i - 1][j] + pre_b[i][j - 1] - pre_b[i - 1][j - 1] + (color[i][j] == 'B' ? 1 : 0);
}
}
int ans = -1;
int ansx1 = -1;
int ansy1 = -1;
int ansx2 = -1;
int ansy2 = -1;
int flag = 0;
for (int x1 = 1; x1 <= n; x1++) {
for (int x2 = x1; x2 <= n; x2++) {
for (int y1 = 1, y2 = 0; y1 <= n; y1++) {
while (y2 < m && check1(x1, y1, x2, y2 + 1, k) != 0) {
y2++;
}
if ((x2 - x1 + 1) * (y2 - y1 + 1) > ans) {
ans = (x2 - x1 + 1) * (y2 - y1 + 1);
ansx1 = x1;
ansy1 = y1;
ansx2 = x2;
ansy2 = y2;
flag = check1(x1, y1, x2, y2 + 1, k);
}
}
}
}
for (int x1 = 1; x1 <= n; x1++) {
for (int x2 = x1; x2 <= n; x2++) {
for (int y1 = 1, y2 = 0; y1 <= n; y1++) {
while (y2 < m && check2(x1, y1, x2, y2 + 1)) {
y2++;
}
if ((x2 - x1 + 1) * (y2 - y1 + 1) > ans) {
ans = (x2 - x1 + 1) * (y2 - y1 + 1);
ansx1 = x1;
ansy1 = y1;
ansx2 = x2;
ansy2 = y2;
flag = 3;
}
}
}
}
cout << ans << endl;
if (flag == 1) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (ansx1 <= i && i <= ansx2 && ansy1 <= j && j <= ansy2) {
cout << 'B';
} else {
cout << color[i][j];
}
}
cout << endl;
}
} else if (flag == 2) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (ansx1 <= i && i <= ansx2 && ansy1 <= j && j <= ansy2) {
cout << 'G';
} else {
cout << color[i][j];
}
}
cout << endl;
}
} else {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (ansx1 <= i && i <= ansx2 && ansy1 <= j && j <= ansy2) {
cout << 'P';
} else {
cout << color[i][j];
}
}
cout << endl;
}
}
return 0;
}