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

#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF LLONG_MAX
#define MINF LLONG_MIN
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>

int pow(int x, int y, int mod) {
    int temp;
    if (y == 0)
        return 1;

    temp = (pow(x, y / 2, mod)) % mod;

    if (y % 2 == 0)
        return (temp * temp) % mod;
    else
        return (((x * temp) % mod) * temp) % mod;
}

int score(vector<int> &v) {

    int ans = 0;

    for(int i = 1; i <= 9; i ++) {

        ans += i * pow(10, v[i]);
    }

    return ans;
}
void solve(int tno) {

    int k; cin >> k;

    vector<int> cards(10, k);
    string S, T;
    cin >> S >> T;

    vector<int> t(10, 0), a(10, 0);

    for(char ch : S) {

        if(ch == '#')
            continue;
        t[ch - '0'] ++;
        cards[ch - '0'] --;
    }

    for(char ch : T) {

        if(ch == '#')
            continue;
        a[ch - '0'] ++;
        cards[ch - '0'] --;
    }

    int taka = 0, aoki = 0;
    for(int i = 1; i <= 9; i ++) {
        for(int j = 1; j <= 9; j ++) {

            if(i == j || cards[i] == 0 || cards[j] == 0) 
                continue;

            t[i] ++;
            a[j] ++;

            if(score(t) > score(a))
                taka += cards[i] * cards[j];
            else
                aoki += cards[i] * cards[j];  

            t[i] --;
            a[j] --;  
        }
    }

    for(int i = 1; i <= 9; i ++) {

        if(cards[i] < 2)
            continue;
        
        t[i] ++;
        a[i] ++;

        if(score(t) > score(a)) {
            taka += cards[i] * (cards[i] - 1);
        }
        else {
            aoki += cards[i] * (cards[i] - 1);
        }

        t[i] --;
        a[i] --;
    }
    // cout << taka << ' ' << (taka + aoki) << endl;
    printf("%.15lf\n", (taka * 1.0) / (taka + aoki));
}

int32_t main() {

    FASTIO

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t;
    t = 1;
    for (int i = 1; i <= t; i ++)
        solve(i);
}
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
ll max(ll a,ll b) {return ((a>b)?a:b);}
ll min(ll a,ll b) {return ((a>b)?b:a);}
vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
void sol(void)
{
cin>>n>>m;
string s[n];
vector<int> r[n];
vector<int> c[m];
int rp[n]={0};
int colp[m]={0};
int cnt=0;
for(int i=0;i<n;i++) 
{
cin>>s[i];
for(int j=0;j<m;j++)
{
if(s[i][j]=='#')
r[i].pb(j),c[j].pb(i);
else
cnt++;
}
}
ll ans=0;
ll cc;
temp=power(2,cnt);
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        if(s[i][j]=='#')
        continue;
        while(rp[i]<r[i].size() && r[i][rp[i]]<j)
        rp[i]++;
        int right=((rp[i]<r[i].size())?r[i][rp[i]]:m);
        int left=-1;
        if(rp[i]>0)
        left=r[i][rp[i]-1];
        ll calc=temp+mod;
        cc=right-left-1;
        int up=-1;
        int down=n;
        while(colp[j]<c[j].size() && c[j][colp[j]]<i)
        colp[j]++;
        if(colp[j]<c[j].size())
        down=c[j][colp[j]];
        if(colp[j]>0)
        up=c[j][colp[j]-1];
        cc+=down-up-1;
        cc--;
        ll calc2=(power(2,cnt-cc));
        calc-=calc2;
        calc%=mod;
        ans+=calc;
        ans%=mod;
    }
}
cout<<ans;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}
