using namespace std;
typedef struct Pos{
int x;
int y;
int step;
};
Pos start,temp,t,rout[100];
int cunt,col,row,delta[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
char map[15][15];
bool visit[15][15];
double M,R;
int Check(int c)
{
// for(int i=0;i<c;i++)
// printf("%d %d/n",rout[i].x,rout[i].y);
for(int i=0;i<c;i++)
if(map[rout[i].x][rout[i].y]=='M')
return true;
return false;
}
void Dfs(int x1,int y1,int cunt,int c)
{
// printf("%d %d %d %d/n",x1,y1,cunt,c);
if(cunt==0&&map[x1][y1]=='S')
{
R++;
if(Check(c))
M++;
//printf("/n");
}
if(cunt>0)
{
visit[x1][y1]=true;
for(int i=0;i<4;i++)
{
int x2=x1+delta[i][0];
int y2=y1+delta[i][1];
if(!visit[x2][y2]&&x2>=0&&x2<col&&y2>=0&&y2<row&&map[x2][y2]!='#')
{
rout[c].x=x2;
rout[c].y=y2;
Dfs(x2,y2,cunt-1,c+1);
}
}
}
visit[x1][y1]=false;
}
void Bfs()
{
queue<Pos> q;
visit[start.x][start.y]=true;
start.step=0;
q.push(start);
while(!q.empty())
{
temp=q.front();
q.pop();
//printf("%d %d %d %d %d/n",temp.x,temp.y,temp.step,temp.r,pre[temp.r].r);
if(map[temp.x][temp.y]=='T')
{
// printf("%d/n",temp.step);
memset(visit,false,sizeof(visit));
rout[0].x=temp.x;
rout[0].y=temp.y;
Dfs(temp.x,temp.y,temp.step,1);
break;
}
for(int i=0;i<4;i++)
{
t.x=temp.x+delta[i][0];
t.y=temp.y+delta[i][1];
if(t.x>=0&&t.y>=0&&t.x<col&&t.y<row&&!visit[t.x][t.y]&&map[t.x][t.y]!='#')
{
t.step=temp.step+1;
visit[t.x][t.y]=true;
q.push(t);
}
}
}
}
int main()
{
freopen("data.in","r",stdin);
int test,cas=1;
scanf("%d",&test);
while(test--)
{
M=0;R=0;
scanf("%d%d",&col,&row);
memset(visit,false,sizeof(visit));
getchar();
for(int i=0;i<col;i++)
{
gets(map[i]);
for(int j=0;j<row;j++)
if(map[i][j]=='S')
{
start.x=i;
start.y=j;
}
}
Bfs();
// printf("%lf %lf/n",R,M);
printf("Mission #%d:/n",cas++);
if(R!=M)
{
printf("The probability for the spy to get to the telegraph transmitter is ");
printf("%.2lf",100*((R-M)/R));
cout<<"%."<<endl<<endl;
}
else
printf("Mission Impossible./n/n");
}
while(1);
return 0;
}