#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);
  }
}