#include<bits/stdc++.h>
using namespace std;
char s[35][85];
char ch;
long dr[]={1,0,-1,0};
long dc[]={0,1,0,-1};
long cnt=0;
void dfs(long x,long y)
{
long i1,dx,dy;
for(i1=0;i1<4;i1++)
{
dx=x+dr[i1];
dy=y+dc[i1];
if(s[dx][dy]==ch||s[dx][dy]=='X')
continue;
else
{
s[dx][dy]=ch;
dfs(dx,dy);
}
}
}
main()
{
while(gets(s[0]))
{
cnt=1;
while(gets(s[cnt]))
{
if(s[cnt][0]=='_')
break;
cnt++;
}
long i,j;
for(i=0;i<cnt;i++)
{
for(j=0;j<strlen(s[i]);j++)
{
if(s[i][j]!=' '&&s[i][j]!='X')
{
ch=s[i][j];
s[i][j]=' ';
dfs(i,j);
s[i][j]=ch;
}
}
}
for(i=0;i<=cnt;i++)
printf("%s\n",s[i]);
}
}
using namespace std;
char s[35][85];
char ch;
long dr[]={1,0,-1,0};
long dc[]={0,1,0,-1};
long cnt=0;
void dfs(long x,long y)
{
long i1,dx,dy;
for(i1=0;i1<4;i1++)
{
dx=x+dr[i1];
dy=y+dc[i1];
if(s[dx][dy]==ch||s[dx][dy]=='X')
continue;
else
{
s[dx][dy]=ch;
dfs(dx,dy);
}
}
}
main()
{
while(gets(s[0]))
{
cnt=1;
while(gets(s[cnt]))
{
if(s[cnt][0]=='_')
break;
cnt++;
}
long i,j;
for(i=0;i<cnt;i++)
{
for(j=0;j<strlen(s[i]);j++)
{
if(s[i][j]!=' '&&s[i][j]!='X')
{
ch=s[i][j];
s[i][j]=' ';
dfs(i,j);
s[i][j]=ch;
}
}
}
for(i=0;i<=cnt;i++)
printf("%s\n",s[i]);
}
}