#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = int64_t;

ll score(string S){
    vector<ll> cnt(10);
    iota(cnt.begin(), cnt.end(), 0);
    for(char c : S) cnt[c - '0'] *= 10;
    return accumulate(cnt.begin(), cnt.end(), 0);
}
int main(){
    ll K;
    string S, T;
    cin >> K >> S >> T;
    vector<ll> cnt(10, K);
    for(char c : S + T) cnt[c - '0']--;
    ll win = 0;
    for(ll x = 1; x <= 9; x++) for(ll y = 1; y <= 9; y++){
        S.back() = '0' + x;
        T.back() = '0' + y;
        if(score(S) <= score(T)) continue;
        win += cnt [x] * (cnt [y] - (x == y)); 
    } 
    const ll rem = 9 * K - 8; 
    cout << double (win) / rem / (rem - 1) << endl; 
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >

//chrono::system_clock::time_point start, end;
clock_t start;

bool did[50*52];
int tile[51][51];
int point[51][51];
int N = 50;
int si,sj;

string now = "";
int len = 0;
string ans="";

int score = 0;
int best_s = 0;

string D = "DURL";
int di[] = {1,-1,0,0};
int dj[] = {0,0,1,-1};

void calc(int i,int j,char &x){
  if(i<0 || j<0 || i>=50 || j>=50)return;
  if(did[ tile[i][j] ])return;
  clock_t end = clock();
  double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if(time >= 1950)return;


  now[len] = x;
  len++;
  did[ tile[i][j] ] = true;
  score += point[i][j];

  if(score > best_s){
    best_s = score;
    ans = now.substr(0,len);
  }


  FOR(k,0,4){
    calc(i+di[k],j+dj[k],D[k]);
  }


  len--;
  did[ tile[i][j] ] = false;
  score -= point[i][j];
}


int main(){
  FOR(i,0,N*N) now += 'D';

  mt19937_64 mt(1);
  uniform_real_distribution<double> rnd(0.00,1.00);
  
  cin >> si >> sj;
  FOR(i,0,N)FOR(j,0,N){
    cin >> tile[i][j];
  }
  FOR(i,0,N)FOR(j,0,N){
    cin >> point[i][j];
  }

  start = clock();

  char a = 'U';
  calc(si,sj,a);

  if(ans.size() == 0) ans = "U";
  cout << ans.substr(1,ans.size()-1) << endl;

}

