#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,W,a,b;
  cin >> N >> W >> a >> b;
  vector<vector<char>> data(N, vector<char>(W));
  for (int i=0;i<N;i++){
    for(int j=0;j<W;j++){
      cin >> data[i][j];
    }
  }
  int count =-3;
  for(int i =b-1;i<W;i++){
    if(data[a-1][i]=='.') count++;
    else break;
  }
  for(int i =b-1;i>-1;i--){
    if(data[a-1][i]=='.') count++;
    else break;
  }
  for(int i =a-1;i<N;i++){
    if(data[i][b-1]=='.') count++;
    else break;
  }
  for(int i =a-1;i>-1;i--){
    if(data[i][b-1]=='.') count++;
    else break;
  }
  
  cout << count <<endl; 
}
/*
    I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
/*-------typedefs------*/
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
}
/*-------- test-case stuff--------------*/
#define ssolve solve();
#define msolve int T;cin >> T;while(T--) {solve();}
#define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
ll score(string s) {
    vector<ll> cnt(10);
    iota(all(cnt), 0);
    for(char c : s) cnt[c - '0'] *= 10;
    return accumulate(all(cnt), 0); 
}

void solve() {
    ll k;cin >> k;
    string S, T;
    cin >> S >> T;

    vector<ll> cnt(10, k);
    for(char c : S + T) cnt[c - '0']--;
    ll win = 0;
    for(ll x = 1;x < 10;x++) for(ll y = 1;y < 10;y++) {
        S.back() = '0' + x;
        T.back() = '0' + y;
        if(score(S) <= score(T)) continue;
        win += cnt[x] * (cnt[y] - (x == y));
    }

    ll rem = 9 * k - 8;
    double ans = (1.0 * win) / (1.0 * rem * (rem - 1));
    cout << fixed << setprecision(10) << ans << endl;
}

int main() {
    go();
    ssolve
    return 0;
}
