1 #include <cstdio>
2 #include <iostream>
3 #include <cstring>
4 using namespace std;
5 int T,n,m,head,tail,px,py,qx,qy,state[20010][5],dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
6 bool vis[110][110];
7 char a[110][110];
8 double l;
9 bool pd(int x,int y)
10 {
11 if (x<=0||y<=0||x>n||y>m||vis[x][y]||a[x][y]=='#') return false;
12 return true;
13 }
14 void bfs()
15 {
16 head=0,tail=1,state[1][1]=px,state[1][2]=py,vis[px][py]=1;
17 while (head<tail)
18 {
19 head++;
20 for (int i=0;i<4;i++)
21 {
22 int x=state[head][1]+dx[i],y=state[head][2]+dy[i];
23 if (pd(x,y))
24 {
25 tail++,state[tail][1]=x,state[tail][2]=y,vis[x][y]=1;
26 if (x==state[head][1]) state[tail][3]=state[head][3]+1,state[tail][4]=state[head][4];
27 else state[tail][3]=state[head][3],state[tail][4]=state[head][4]+1;
28 if (x==qx&&y==qy&&l>=state[tail][3])
29 {
30 printf("%.5lf
",(l-state[tail][3])/state[tail][4]);
31 return;
32 }
33 if (x==qx&&y==qy) tail--,vis[qx][qy]=0;
34 }
35 }
36 }
37 }
38 int main()
39 {
40 freopen("maze.in","r",stdin),freopen("maze.out","w",stdout);
41 scanf("%d",&T);
42 while (T--)
43 {
44 memset(vis,0,sizeof(vis)),memset(state,0,sizeof(state));
45 scanf("%lf%d%d",&l,&n,&m);
46 for (int i=1;i<=n;i++)
47 {
48 scanf("
");
49 for (int j=1;j<=m;j++)
50 {
51 a[i][j]=getchar();
52 if (a[i][j]=='S') px=i,py=j;
53 if (a[i][j]=='E') qx=i,qy=j;
54 }
55 }
56 bfs();
57 }
58 }