/**
*    author:  shu8Cream
*    created: 26.04.2021 09:06:13
**/

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using namespace std::chrono;
inline double get_time_sec(void){
    return static_cast<double>(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count())/1000000000;
}

int si,sj;
vvi t(50,vi(50));
vvi p(50,vi(50));

string finans = "";
int finscore = 0;

const vi di = {1,0,-1,0};
const vi dj = {0,1,0,-1};

void input(){
    cin >> si >> sj;
    rep(i,50)rep(j,50) cin >> t[i][j];
    rep(i,50)rep(j,50) cin >> p[i][j];
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    input();

    set<int> allrem;
    int loop = 20;
    while(loop--){
        double start = get_time_sec();
        int score = 0;
        string ans = "";
        vector<P> remcell;

        while(get_time_sec() - start<0.098){

            int tscore = 0;
            string tans = "";
            set<int> rem;
            queue<P> pq;
            pq.push({si,sj});
            int i=0,j=0;
            while(!pq.empty()){
                int pi=i,pj=j;
                tie(i,j) = pq.front(); pq.pop();
                remcell.push_back({i,j});
                rem.insert(t[i][j]);
                tscore += p[i][j];
                queue<P> emp;
                swap(pq,emp);

                if(!(i == si && j == sj)){
                    if(i-pi==1) tans+="D";
                    else if(i-pi==-1) tans+="U";
                    else if(j-pj==1) tans+="R";
                    else if(j-pj==-1) tans+="L";
                }

                // cout << ans << endl;

                vi rand = {0,1,2,3};

                std::random_device seed_gen;
                std::mt19937 engine(seed_gen());
                shuffle(all(rand),engine);
                for(auto k : rand){
                    int ni = i + di[k];
                    int nj = j + dj[k];
                    if(ni<0 || ni>=50 || nj<0 || nj>=50) continue;
                    if(t[i][j]==t[ni][nj]) continue;
                    if(rem.count(t[ni][nj])) continue;
                    if(allrem.count(t[ni][nj])) continue;

                    int ngcnt = 0;
                    rep(kk,4){
                        int nni = ni + di[kk];
                        int nnj = nj + dj[kk];
                        if(nni<0 || nni>=50 || nnj<0 || nnj>=50) {ngcnt++; continue;}
                        if(t[nni][nnj]==t[ni][nj]) {ngcnt++; continue;}
                        if(rem.count(t[nni][nnj])) {ngcnt++; continue;}
                        if(allrem.count(t[nni][nnj])) {ngcnt++; continue;}
                    }
                    if(ngcnt==4) continue;

                    pq.push({ni,nj}); 
                }
            }

            if(tscore>score){
                score = tscore;
                ans = tans;
            }

        }

        int anslen = (ans.size()+1)/2;
        ans = ans.substr(0,anslen);
        
        finans += ans;

        allrem.insert(t[si][sj]);
        rep(k,anslen){
            if(ans[k]=='U') si--;
            if(ans[k]=='D') si++;
            if(ans[k]=='L') sj--;
            if(ans[k]=='R') sj++;
            allrem.insert(t[si][sj]);
        }
    }
    cout << finans << endl;
}
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef vector<bool> VB;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) LL((a).size())

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL LARGE_INT = 1e9+100;
const LL INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const LL MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL TIME_LIMIT = 1990;

LL start_time;
string result_string;
LL result_point=0;
LL h=50;
LL w=50;
VVL t;
VVL p;

void check(string result, LL point){
    if(point > result_point){
        result_point = point;
        result_string = result;
    }
}

void dfs(LL x, LL y, VB v, string result, LL point){
    LL time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
    if(time-start_time > TIME_LIMIT){
        check(result, point);
        return;
    }

    v[t[x][y]]=true;

    VL dx={1,-1,0,0};
    VL dy={0,0,1,-1};

    VVL tp;

    REP(i,4){
        LL nx = x+dx[i];
        LL ny = y+dy[i];
        if(nx >= h || nx < 0 || ny >= w || ny < 0){
            continue;
        }
        if(v[t[nx][ny]]){
            continue;
        }

        tp.PB({p[nx][ny],i,nx,ny});
    }

    if(tp.empty()){
        check(result, point);
        return;
    }

    SORT_DESC(tp);

    for(auto w : tp){
        LL np = w[0];
        LL i = w[1];
        LL nx = w[2];
        LL ny = w[3];
        //cerr<<np<<" "<<i<<" "<<nx<<" "<<ny<<endl;
        string d;
        if(i==0){
            d = "D";
        }
        if(i==1){
            d = "U";
        }
        if(i==2){
            d = "R";
        }
        if(i==3){
            d = "L";
        }
        dfs(nx, ny, v, result+d, point+np);
    }
}

void Main()
{
    start_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
    //dump(start_time)
    LL si,sj;cin>>si>>sj;

    t.resize(h);
    REP(i,h){
        t[i].resize(w);
        REP(j,w){
            cin>>t[i][j];
        }
    }
    p.resize(h);
    REP(i,h){
        p[i].resize(w);
        REP(j,w){
            cin>>p[i][j];
        }
    }


    VB v(h*w);
    string result = "";
    LL point = 0;

    dfs(si, sj, v, result, point);

    cout<<result_string<<endl;

    
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}