#include <iostream>
using namespace std;
bool vis[1001][1001];
char c[1001][1001];
int m,n;
int rec(int i1,int j1)
{
//cout<<i1<<" "<<j1<<endl;
if(i1+1<m&&!vis[i1+1][j1]&&c[i1+1][j1]=='f')
{
vis[i1+1][j1]=1;
return 1;
}
if(i1+1<m&&!vis[i1+1][j1]&&c[i1+1][j1]=='b')
{
vis[i1+1][j1]=1;
if(rec(i1+1,j1))
return 1;
vis[i1+1][j1]=0;
}
if(i1-1>=0&&!vis[i1-1][j1]&&c[i1-1][j1]=='f')
{
vis[i1-1][j1]=1;
return 1;
}
if(i1-1>=0&&!vis[i1-1][j1]&&c[i1-1][j1]=='b')
{
vis[i1-1][j1]=1;
if(rec(i1-1,j1))
return 1;
vis[i1-1][j1]=0;
}
if(j1+1<n&&!vis[i1][j1+1]&&c[i1][j1+1]=='f')
{
vis[i1][j1+1]=1;
return 1;
}
if(j1+1<n&&!vis[i1][j1+1]&&c[i1][j1+1]=='b')
{
vis[i1][j1+1]=1;
if(rec(i1,j1+1))
return 1;
vis[i1][j1+1]=0;
}
if(j1-1>=0&&!vis[i1][j1-1]&&c[i1][j1-1]=='f')
{
vis[i1][j1-1]=1;
return 1;
}
if(j1-1>=0&&!vis[i1][j1-1]&&c[i1][j1-1]=='b')
{
vis[i1][j1-1]=1;
if(rec(i1,j1-1))
return 1;
vis[i1][j1-1]=0;
}
return 0;
}
int main()
{
int t,i1,j1;
cin>>t;
while(t--)
{
cin>>m>>n;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>c[i][j];
if(c[i][j]=='s')
{
i1=i;
j1=j;
}
}
}
vis[i1][j1]=1;
if(rec(i1,j1))
for(int i=0;i<m;cout<<endl,i++)
for(int j=0;j<n;vis[i][j]=0,j++)
if(vis[i][j])
cout<<c[i][j];
else
cout<<'-';
else
cout<<"The path doesn't exist."<<endl;
vis[i1][j1]=0;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpib29sIHZpc1sxMDAxXVsxMDAxXTsKY2hhciBjWzEwMDFdWzEwMDFdOwppbnQgbSxuOwppbnQgcmVjKGludCBpMSxpbnQgajEpCnsKICAgIC8vY291dDw8aTE8PCIgIjw8ajE8PGVuZGw7CiAgICBpZihpMSsxPG0mJiF2aXNbaTErMV1bajFdJiZjW2kxKzFdW2oxXT09J2YnKQogICAgewogICAgICAgIHZpc1tpMSsxXVtqMV09MTsKICAgICAgICByZXR1cm4gMTsKICAgIH0KICAgIGlmKGkxKzE8bSYmIXZpc1tpMSsxXVtqMV0mJmNbaTErMV1bajFdPT0nYicpCiAgICB7CiAgICAgICAgdmlzW2kxKzFdW2oxXT0xOwogICAgICAgIGlmKHJlYyhpMSsxLGoxKSkKICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgdmlzW2kxKzFdW2oxXT0wOwogICAgfQogICAgaWYoaTEtMT49MCYmIXZpc1tpMS0xXVtqMV0mJmNbaTEtMV1bajFdPT0nZicpCiAgICB7CiAgICAgICAgdmlzW2kxLTFdW2oxXT0xOwogICAgICAgIHJldHVybiAxOwogICAgfQogICAgaWYoaTEtMT49MCYmIXZpc1tpMS0xXVtqMV0mJmNbaTEtMV1bajFdPT0nYicpCiAgICB7CiAgICAgICAgdmlzW2kxLTFdW2oxXT0xOwogICAgICAgIGlmKHJlYyhpMS0xLGoxKSkKICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgdmlzW2kxLTFdW2oxXT0wOwogICAgfQogICAgaWYoajErMTxuJiYhdmlzW2kxXVtqMSsxXSYmY1tpMV1bajErMV09PSdmJykKICAgIHsKICAgICAgICB2aXNbaTFdW2oxKzFdPTE7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CiAgICBpZihqMSsxPG4mJiF2aXNbaTFdW2oxKzFdJiZjW2kxXVtqMSsxXT09J2InKQogICAgewogICAgICAgIHZpc1tpMV1bajErMV09MTsKICAgICAgICBpZihyZWMoaTEsajErMSkpCiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHZpc1tpMV1bajErMV09MDsKICAgIH0KICAgIGlmKGoxLTE+PTAmJiF2aXNbaTFdW2oxLTFdJiZjW2kxXVtqMS0xXT09J2YnKQogICAgewogICAgICAgIHZpc1tpMV1bajEtMV09MTsKICAgICAgICByZXR1cm4gMTsKICAgIH0KICAgIGlmKGoxLTE+PTAmJiF2aXNbaTFdW2oxLTFdJiZjW2kxXVtqMS0xXT09J2InKQogICAgewogICAgICAgIHZpc1tpMV1bajEtMV09MTsKICAgICAgICBpZihyZWMoaTEsajEtMSkpCiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHZpc1tpMV1bajEtMV09MDsKICAgIH0KICAgIHJldHVybiAwOyAgICAKfQppbnQgbWFpbigpCnsKICAgIGludCB0LGkxLGoxOwogICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIGNpbj4+bT4+bjsKICAgICAgICBmb3IoaW50IGk9MDtpPG07aSsrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGludCBqPTA7ajxuO2orKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY2luPj5jW2ldW2pdOwogICAgICAgICAgICAgICAgaWYoY1tpXVtqXT09J3MnKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGkxPWk7CiAgICAgICAgICAgICAgICAgICAgajE9ajsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2aXNbaTFdW2oxXT0xOwogICAgICAgIGlmKHJlYyhpMSxqMSkpCiAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bTtjb3V0PDxlbmRsLGkrKykKICAgICAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8bjt2aXNbaV1bal09MCxqKyspCiAgICAgICAgICAgICAgICAgICAgaWYodmlzW2ldW2pdKQogICAgICAgICAgICAgICAgICAgICAgICBjb3V0PDxjW2ldW2pdOwogICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgY291dDw8Jy0nOwogICAgICAgIGVsc2UKICAgICAgICAgICAgY291dDw8IlRoZSBwYXRoIGRvZXNuJ3QgZXhpc3QuIjw8ZW5kbDsKICAgICAgICB2aXNbaTFdW2oxXT0wOwogICAgfQogICAgcmV0dXJuIDA7Cn0gIA==