#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char str[1001][1001];
bool mat[1001][1001];
int n,m;
bool func(int a,int b)
{
//cout<<a<<" "<<b<<"\n";
if(str[a][b]=='f')
return true;
if(a<n-1 && (str[a+1][b]=='b' ||str[a+1][b]=='f' ) && mat[a+1][b]==false)
{mat[a][b]=true;bool x=func(a+1,b);if(x){str[a][b]='-';return true;}}
if(a>0 && (str[a-1][b]=='b' || str[a-1][b]=='f')&& mat[a-1][b]==false)
{mat[a][b]=true;bool x=func(a-1,b);if(x){str[a][b]='-';return true;}}
if(b<m-1 && (str[a][b+1]=='b' || str[a][b+1]=='f')&& mat[a][b+1]==false)
{mat[a][b]=true;bool x=func(a,b+1);if(x){str[a][b]='-';return true;}}
if(b>0 && (str[a][b-1]=='b' || str[a][b-1]=='f')&& mat[a][b-1]==false)
{mat[a][b]=true;bool x=func(a,b-1);if(x){str[a][b]='-';return true;}}
return false;
}
main()
{
int t,a,b;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d %d",&n,&m);
for(int j=0;j<n;j++)
for(int k=0;k<m;k++)
mat[j][k]=false;
for(int j=0;j<n;j++)
scanf("%s",&str[j]);
for(int j=0;j<n;j++)
for(int k=0;k<m;k++)
if(str[j][k]=='s')
{a=j;b=k;break;}
if(func(a,b))
{
for(int j=0;j<n;j++)
for(int k=0;k<m;k++)
{if(str[j][k]=='-')
str[j][k]='b';
else if(str[j][k]=='w' || str[j][k]=='b')
str[j][k]='-';}
str[a][b]='s';
for(int j=0;j<n;j++)
printf("%s\n",str[j]);
}
else
printf("The path doesn't exist.\n");
}
// system("pause");
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPGNzdGRpbz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY2hhciBzdHJbMTAwMV1bMTAwMV07CmJvb2wgbWF0WzEwMDFdWzEwMDFdOwppbnQgbixtOwpib29sIGZ1bmMoaW50IGEsa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m0pOwogICAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspCiAgICAgICAgICAgICAgZm9yKGludCBrPTA7azxtO2srKykKICAgICAgICAgICAgICBtYXRbal1ba109ZmFsc2U7CiAgICAgICAgICAgICAgZm9yKGludCBqPTA7ajxuO2orKykKICAgICAgICAgICAgICBzY2FuZigiJXMiLCZzdHJbal0pOwogICAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspCiAgICAgICAgICAgICAgZm9yKGludCBrPTA7azxtO2srKykKICAgICAgICAgICAgICBpZihzdHJbal1ba109PSdzJykKICAgICAgICAgICAgICB7YT1qO2I9azticmVhazt9CmlmKGZ1bmMoYSxiKSkKewogICAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspCiAgICAgICAgICAgICAgZm9yKGludCBrPTA7azxtO2srKykKICAgICAgICAgICAgICB7aWYoc3RyW2pdW2tdPT0nLScpCiAgICAgICAgICAgICAgIHN0cltqXVtrXT0nYic7CiAgICAgICAgICAgICAgIGVsc2UgaWYoc3RyW2pdW2tdPT0ndycgfHwgc3RyW2pdW2tdPT0nYicpCiAgICAgICAgICAgICAgIHN0cltqXVtrXT0nLSc7fQogICAgICAgICAgICAgICBzdHJbYV1bYl09J3MnOwogICAgICAgICAgICAgICBmb3IoaW50IGo9MDtqPG47aisrKQogICAgICAgICAgICAgIHByaW50ZigiJXNcbiIsc3RyW2pdKTsKICAgICAgICAgICAgICAKICAgICAgICAgICAgICAKfQplbHNlCnByaW50ZigiVGhlIHBhdGggZG9lc24ndCBleGlzdC5cbiIpOwogCn0KIAogCiAKIAogICAgICAgICAvLyBzeXN0ZW0oInBhdXNlIik7CiAgICAgIH0=