#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
ll R,C;
char g[ 21 ] [ 21 ] ;
ll dx[ ] = { 1 ,0 ,- 1 ,0 } ;
ll dy[ ] = { 0 ,1 ,0 ,- 1 } ;
ll STEP;
double P,Q;
ll cnt[ 21 ] [ 21 ] ;
double maxx,ans;
bool check( ll x , ll y) {
if ( x< 0 || x>= R || y< 0 || y>= C)
return 0 ;
return 1 ;
}
void go( ll x, ll y , ll l) {
//cout << "here" << endl;
double prd = 1.0 ;
double prob = P;
if ( g[ x] [ y] == '.' )
prob = Q;
ll i,j,k;
for ( i = 0 ; i < cnt[ x] [ y] ; i++ )
prd * = ( 1.0 - prob) ;
prd * = prob;
ans + = prd;
cnt[ x] [ y] ++ ;
if ( l < STEP) {
for ( i = 0 ; i < 4 ; i++ ) {
if ( check( x+ dx[ i] ,y+ dy[ i] ) )
go( x+ dx[ i] ,y+ dy[ i] ,l+ 1 ) ;
}
} else
maxx = max( ans,maxx) ;
cnt[ x] [ y] -- ;
ans - = prd;
}
int main( ) {
boost;
ll T,N,i,j,k,Rs,Cs;
cin >> T;
ll ind;
for ( ind = 1 ; ind <= T ; ind++ ) {
cin >> R >> C >> Rs >> Cs >> STEP ;
cin >> P >> Q;
for ( i = 0 ; i < R ; i++ ) {
for ( j = 0 ; j < C ; j++ )
cnt[ i] [ j] = 0 ;
}
for ( i = 0 ; i < R ; i++ ) {
for ( j = 0 ; j < C ; j++ ) {
cin >> g[ i] [ j] ;
}
}
// cout << "here" << endl;
maxx = ans = 0.0 ;
if ( STEP > 0 ) {
for ( i = 0 ; i < 4 ; i++ ) {
if ( check( Rs+ dx[ i] ,Cs+ dy[ i] ) )
go( Rs+ dx[ i] ,Cs+ dy[ i] ,1 ) ;
}
}
printf ( "Case #%lld: %.10lf\n " ,ind,maxx) ;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY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iBBIC4gLg==
2
4 4 0 0 5
0.8000 0.2000
. . . .
. . . .
. . A .
. A . A
10 10 9 1 4
0.6121 0.1000
. . A A . . . . . .
A . . . . . . . . .
. . A . . . . A . .
. . . A A . . . . .
. A A A . . . . . A
A . A A . . . . A .
. A . . . . . A . .
. . . . A A . . . .
. . A . . . A . . A
. . . . A . . A . .