#include<bits/stdc++.h>
using namespace std;
map< char ,int > m;
string a,b[ 35 ] ;
bool visited[ 40 ] [ 100 ] ;
int dx[ ] = { 1 ,0 ,- 1 ,0 } ;
int dy[ ] = { 0 ,1 ,0 ,- 1 } ;
void dfs( int x,int y,char p) {
visited[ x] [ y] = true ;
for ( int i= 0 ; i< 4 ; i++ ) {
int xx = x + dx[ i] ;
int yy = y + dy[ i] ;
if ( visited[ xx] [ yy] == false && b[ xx] [ yy] == ' ' ) {
b[ xx] [ yy] = p;
dfs( xx,yy,p) ;
}
}
}
int main( ) {
int i= 0 ;
while ( getline( cin ,a) ) {
char mp[ 2000 ] ;
if ( a[ 0 ] == '_' ) {
int num= 0 ;
for ( int k= 0 ; k< i- 1 ; k++ ) {
for ( int j= 0 ; j< b[ k] .size ( ) ; j++ ) {
if ( m.find ( b[ k] [ j] ) == m.end ( ) ) {
mp[ num] = b[ k] [ j] ;
num++ ;
m[ b[ k] [ j] ] = 1 ;
}
else {
m[ b[ k] [ j] ] ++ ;
}
}
}
int ma= 0 ;
char bun;
for ( int z= 0 ; z< num; z++ ) {
if ( mp[ z] == ' ' ) continue ;
//cout<<mp[z]<<" "<<m[mp[z]]<<"\n";
if ( m[ mp[ z] ] > ma) {
ma = m[ mp[ z] ] ;
bun = mp[ z] ;
}
}
//cout<<bun<<"\n";
for ( int k= 0 ; k< i- 1 ; k++ ) {
for ( int j= 0 ; j< b[ k] .size ( ) ; j++ ) {
if ( b[ k] [ j] ! = ' ' && b[ k] [ j] ! = bun && visited[ k] [ j] == false ) {
dfs( k,j,b[ k] [ j] ) ;
}
}
}
for ( int k= 0 ; k< i; k++ ) {
cout << b[ k] << "\n " ;
}
cout << a<< "\n " ;
i= 0 ;
m.clear ( ) ;
memset ( visited,false ,sizeof ( visited) ) ;
}
else {
b[ i] = a;
i++ ;
}
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCm1hcDxjaGFyLGludD5tOwpzdHJpbmcgYSxiWzM1XTsKYm9vbCB2aXNpdGVkWzQwXVsxMDBdOwppbnQgZHhbXT17MSwwLC0xLDB9OwppbnQgZHlbXT17MCwxLDAsLTF9OwoKdm9pZCBkZnMoaW50IHgsaW50IHksY2hhciBwKXsKCiAgICB2aXNpdGVkW3hdW3ldPXRydWU7CiAgICBmb3IoaW50IGk9MDtpPDQ7aSsrKXsKICAgICAgICBpbnQgeHggPSB4ICsgZHhbaV07CiAgICAgICAgaW50IHl5ID0geSArIGR5W2ldOwogICAgICAgIGlmKHZpc2l0ZWRbeHhdW3l5XT09ZmFsc2UgJiYgYlt4eF1beXldPT0nICcpewogICAgICAgICAgICBiW3h4XVt5eV0gPSBwOwogICAgICAgICAgICBkZnMoeHgseXkscCk7CiAgICAgICAgfQogICAgfQoKfQoKaW50IG1haW4oKXsKCiAgICBpbnQgaT0wOwogICAgd2hpbGUoZ2V0bGluZShjaW4sYSkpewoKICAgICAgICBjaGFyIG1wWzIwMDBdOwoKICAgICAgICBpZihhWzBdPT0nXycpewoKICAgICAgICAgICAgaW50IG51bT0wOwogICAgICAgICAgICBmb3IoaW50IGs9MDtrPGktMTtrKyspewogICAgICAgICAgICAgICAgZm9yKGludCBqPTA7ajxiW2tdLnNpemUoKTtqKyspewogICAgICAgICAgICAgICAgICAgIGlmKG0uZmluZChiW2tdW2pdKT09bS5lbmQoKSl7CiAgICAgICAgICAgICAgICAgICAgICAgIG1wW251bV09YltrXVtqXTsKICAgICAgICAgICAgICAgICAgICAgICAgbnVtKys7CiAgICAgICAgICAgICAgICAgICAgICAgIG1bYltrXVtqXV0gPSAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBlbHNlewogICAgICAgICAgICAgICAgICAgICAgICBtW2Jba11bal1dKys7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CgogICAgICAgICAgICBpbnQgbWE9MDsKICAgICAgICAgICAgY2hhciBidW47CiAgICAgICAgICAgIGZvcihpbnQgej0wO3o8bnVtO3orKyl7CiAgICAgICAgICAgICAgICBpZihtcFt6XT09JyAnKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIC8vY291dDw8bXBbel08PCIgIjw8bVttcFt6XV08PCJcbiI7CiAgICAgICAgICAgICAgICBpZihtW21wW3pdXT4gbWEpIHsKICAgICAgICAgICAgICAgICAgICBtYSA9IG1bbXBbel1dIDsKICAgICAgICAgICAgICAgICAgICBidW4gPSBtcFt6XTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgLy9jb3V0PDxidW48PCJcbiI7CgogICAgICAgICAgICBmb3IoaW50IGs9MDtrPGktMTtrKyspewogICAgICAgICAgICAgICAgZm9yKGludCBqPTA7ajxiW2tdLnNpemUoKTtqKyspewogICAgICAgICAgICAgICAgICAgIGlmKGJba11bal0hPScgJyAmJiBiW2tdW2pdIT1idW4gJiYgdmlzaXRlZFtrXVtqXT09ZmFsc2UpewogICAgICAgICAgICAgICAgICAgICAgICBkZnMoayxqLGJba11bal0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgZm9yKGludCBrPTA7azxpO2srKyl7CiAgICAgICAgICAgICAgICBjb3V0PDxiW2tdPDwiXG4iOwogICAgICAgICAgICB9CgoKICAgICAgICAgICAgY291dDw8YTw8IlxuIjsKICAgICAgICAgICAgaT0wOwogICAgICAgICAgICBtLmNsZWFyKCk7CiAgICAgICAgICAgIG1lbXNldCh2aXNpdGVkLGZhbHNlLHNpemVvZih2aXNpdGVkKSk7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGJbaV09YTsKICAgICAgICAgICAgaSsrOwogICAgICAgIH0KCgogICAgfQoKCgp9Cg==
stdin
ICBYWFhYWFhYWFhYWFhYWFhYWFhYWAogIFggICAgICBYICAgICAgICAgICBYCiAgWCAjICMgIFhYWFhYWFhYIC8gIFgKICBYICAgICAgICAgICAgIFggICAgWAogIFhYWFhYWFhYWFhYWFhYWFhYWFhYCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fCgogICBYWFhYWFhYWFhYWFggICAgICAgWFhYWFhYCiAgWCAgICAgICAjICAgWFhYICBYWFggICBYIFgKICBYICBYWCAgICAgICAgIFggIFggICAgIFggWAogWCAgWCAgWCAgWFhYWFhYWCAgWFhYWFhYWAogWCAgIFhYICAgWAogIFggICAgICAgWCAgWFhYWCAgWFhYWFhYWFgKICAgWFggICAgIFhYWFggIFggIFggIC8gICBYCiAgICBYICAgICAgICAgICBYICBYICAgIC8gWAogICAgWFhYWFhYWFhYWFhYWCAgWFhYWFhYWFgKX19fX19fX19fX19fX19fX19fX19fX19fX19fX18K
XXXXXXXXXXXXXXXXXXXX
X X X
X # # XXXXXXXX / X
X X X
XXXXXXXXXXXXXXXXXXXX
_____________________________
XXXXXXXXXXXX XXXXXX
X # XXX XXX X X
X XX X X X X
X X X XXXXXXX XXXXXXX
X XX X
X X XXXX XXXXXXXX
XX XXXX X X / X
X X X / X
XXXXXXXXXXXXX XXXXXXXX
_____________________________