#include<stdio.h>
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m,sx,sy,xx,yy,visited[1001][1001];
char Cell[1001][1001];
int isSafe(int x, int y)
{
return (x>=0 && y>=0 && x<n && y<m && visited[x][y]==0 && (Cell[x][y] == 'b' || Cell[x][y] == 'f') );
}
int Dfs(int x,int y)
{
//printf("%d %d\n",x,y);
//visited[x][y] = 1;
if(Cell[x][y] == 'f') return 1;
for(int dir=0; dir<4; dir++)
{
xx = x+dx[dir]; yy = y+dy[dir];
if( isSafe(xx,yy) )
{
visited[x][y] = 1;
if( Dfs(xx,yy) ) { Cell[x][y] = 'x'; return 1; }
}
}
return 0;
}
int main()
{
int i,j,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=0; i<n; i++)
for(j=0; j<m; j++)
visited[i][j] = 0;
for(i=0; i<n; i++) scanf("%s",Cell[i]);
for(i=0; i<n; i++)
for(j=0; j<m; j++)
if(Cell[i][j] == 's') { sx=i,sy=j; break; }
if(Dfs(sx,sy))
{
for(i=0; i<n; i++)
{
for(j=0; j<m;j++)
{
if( Cell[i][j] == 'x') Cell[i][j] = 'b' ;
else if( Cell[i][j] == 'w' || Cell[i][j] == 'b' ) Cell[i][j] = '-' ;
}
}
Cell[sx][sy] = 's';
for(i=0; i<n; i++) printf("%s\n",Cell[i]);
}
else printf("The path doesn't exist.\n");
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KCmludCBkeFtdID0gezEsLTEsMCwwfTsKaW50IGR5W10gPSB7MCwwLDEsLTF9OyAKaW50IG4sbSxzeCxzeSx4eCx5eSx2aXNpdGVkWzEwMDFdWzEwMDFdOwpjaGFyIENlbGxbMTAwMV1bMTAwMV07CgppbnQgaXNTYWZlKGludCB4LCBpbnQgeSkKewogICAgcmV0dXJuICh4Pj0wICYmIHk+PTAgJiYgeDxuICYmIHk8bSAmJiB2aXNpdGVkW3hdW3ldPT0wICYmIChDZWxsW3hdW3ldID09ICdiJyB8fCBDZWxsW3hdW3ldID09ICdmJykgKTsKfQoKaW50IERmcyhpbnQgeCxpbnQgeSkKewogICAgLy9wcmludGYoIiVkICVkXG4iLHgseSk7CiAgICAvL3Zpc2l0ZWRbeF1beV0gPSAxOwogICAgaWYoQ2VsbFt4XVt5XSA9PSAnZicpICByZXR1cm4gMTsKICAgIGZvcihpbnQgZGlyPTA7IGRpcjw0OyBkaXIrKykKICAgIHsKICAgICAgICB4eCA9IHgrZHhbZGlyXTsgIHl5ID0geStkeVtkaXJdOwogICAgICAgIGlmKCBpc1NhZmUoeHgseXkpICkgIAogICAgICAgIHsgIAogICAgICAgICAgICB2aXNpdGVkW3hdW3ldID0gMTsgIAogICAgICAgICAgICBpZiggRGZzKHh4LHl5KSApICAgeyAgQ2VsbFt4XVt5XSA9ICd4JzsgIHJldHVybiAxOyAgfQogICAgICAgICAgICAKICAgICAgICB9ICAgCiAgICB9ICAgIAogICAgcmV0dXJuIDA7Cn0KCmludCBtYWluKCkgCnsgCiAgICBpbnQgaSxqLFQ7CiAgICBzY2FuZigiJWQiLCZUKTsKICAgIHdoaWxlKFQtLSkKICAgIHsKICAgICAgIHNjYW5mKCIlZCVkIiwmbiwmbSk7CiAgICAgICBmb3IoaT0wOyBpPG47IGkrKykKICAgICAgICAgZm9yKGo9MDsgajxtOyBqKyspCiAgICAgICAgICAgICAgdmlzaXRlZFtpXVtqXSA9IDA7CgogICAgICAgIGZvcihpPTA7IGk8bjsgaSsrKSAgc2NhbmYoIiVzIixDZWxsW2ldKTsKCiAgICAgICAgZm9yKGk9MDsgaTxuOyBpKyspCiAgICAgICAgIGZvcihqPTA7IGo8bTsgaisrKQogICAgICAgICAgICBpZihDZWxsW2ldW2pdID09ICdzJykgIHsgIHN4PWksc3k9ajsgIGJyZWFrOyAgfQoKICAgICAgICBpZihEZnMoc3gsc3kpKQogICAgICAgIHsKICAgICAgICAgICBmb3IoaT0wOyBpPG47IGkrKykKICAgICAgICAgICB7CiAgICAgICAgICAgICAgZm9yKGo9MDsgajxtO2orKykKICAgICAgICAgICAgICAgeyAgCiAgICAgICAgICAgICAgICAgICBpZiggQ2VsbFtpXVtqXSA9PSAneCcpICBDZWxsW2ldW2pdID0gJ2InIDsKICAgICAgICAgICAgICAgICAgIGVsc2UgaWYoIENlbGxbaV1bal0gPT0gJ3cnIHx8IENlbGxbaV1bal0gPT0gJ2InICkgIENlbGxbaV1bal0gPSAnLScgOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgfQogICAgICAgICAgQ2VsbFtzeF1bc3ldID0gJ3MnOyAKICAgICAgICAgIGZvcihpPTA7IGk8bjsgaSsrKSAgcHJpbnRmKCIlc1xuIixDZWxsW2ldKTsKICAgICAgICB9CiAgICAgICAgZWxzZSAgcHJpbnRmKCJUaGUgcGF0aCBkb2Vzbid0IGV4aXN0LlxuIik7CiAgICB9CiAgcmV0dXJuIDA7Cn0=