var
a:array[0..1000,0..1000] of char;
b:array[0..1000,0..1000] of real;
f:array[0..1000,0..1000] of boolean;
x1,s1,v,h,r,c:longint;
l:real;
proceduremain(x,y,z,s:longint);beginif (x<=0)or(x>r)or(y<=0)or(y>c) thenexit;
if (z>v)and(s>h) thenexit;
if (s>l)and(h<>maxlongint) thenexit;
f[x,y]:=false;
if (x=x1)and(y=s1) thenbegin v:=z;h:=s;end;
if (f[x+1,y])and(b[x+1,y]=0)or(b[x,y]+2<b[x+1,y]) thenbegin
b[x+1,y]:=b[x,y]+2;
main(x+1,y,z+1,s);
end;
if (f[x-1,y])and(b[x-1,y]=0)or(b[x,y]+2<b[x-1,y]) thenbegin
b[x-1,y]:=b[x,y]+2;
main(x-1,y,z+1,s);
end;
if (f[x,y-1])and(b[x,y-1]=0)or(b[x,y]+1<b[x,y-1]) thenbegin
b[x,y-1]:=b[x,y]+1;
main(x,y-1,z,s+1);
end;
if (f[x,y+1])and(b[x,y+1]=0)or(b[x,y]+1<b[x,y+1]) thenbegin
b[x,y+1]:=b[x,y]+1;
main(x,y+1,z,s+1);
end;
f[x,y]:=true;
end;
var
i,j,k,n,x,s:longint;
mid,u:real;
begin
assign(input,'maze.in');reset(input);
assign(output,'maze.out');rewrite(output);
readln(n);
for i:=1to n dobegin
readln(l,r,c);
v:=maxlongint;h:=maxlongint;
fillchar(f,sizeof(f),false);
for j:=1to r dobeginfor k:=1to c dobeginread(a[j,k]);
if a[j,k]<>'#'then f[j,k]:=true;
if a[j,k]='S'thenbegin x:=j;s:=k;end;
if a[j,k]='E'thenbegin x1:=j;s1:=k;end;
end;
readln;
end;
main(x,s,0,0);
mid:=0.50000;
fillchar(b,sizeof(b),0);
u:=v*mid+h;
if u>l then
mid:=mid-(u-l)/v
else mid:=mid+(l-u)/v;
writeln(mid:0:5);
end;
close(input);close(output);
end.