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