#include <iostream>
#include <bits/stdc++.h>

using namespace std;


set<int> stepped;
int t[50][50];
int p[50][50];
int s=0;
int i,j;
char randstep()
{
    vector<char> ds;
    if (i>0 && !stepped.count(t[i-1][j])) ds.push_back('U');
    if (i<49 && !stepped.count(t[i+1][j])) ds.push_back('D');
    if (j>0 && !stepped.count(t[i][j-1])) ds.push_back('L');
    if (j<49 && !stepped.count(t[i][j+1])) ds.push_back('R');
    if (ds.empty()) return '#';
    char w=ds[rand()%ds.size()];
    if (w=='U') i--;
    if (w=='D') i++;
    if (w=='L') j--;
    if (w=='R') j++;
    s+=p[i][j];
    stepped.insert(t[i][j]);
    return w;

}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int si,sj;cin>>si>>sj;
    for (int x=0;x<50;x++){
        for (int y=0;y<50;y++){
            cin >> t[x][y];
        }
    }
    for (int x=0;x<50;x++){
        for (int y=0;y<50;y++){
            cin >> p[x][y];
        }
    }
    int ntries=20;
    srand(42);
    vector<char> bestrun;
    vector<char> attempts[ntries];
    int satts[ntries];
    int best=0;
    set<int> cache={t[si][sj]};
    while (randstep()!='#'){
        for (int k=0;k<ntries;k++){
            s=0;
            i=si;
            j=sj;
            attempts[k].clear();
            stepped=cache;
            char c=randstep();
            while (c!='#'){
                attempts[k].push_back(c);
                c=randstep();
            }
            satts[k]=s;
        }
        long tot[4];
        for (int k=0;k<4;k++) tot[k]=0;
        for (int k=0;k<ntries;k++){
            if (attempts[k][0]=='U') tot[0]+=satts[k];
            if (attempts[k][0]=='D') tot[1]+=satts[k];
            if (attempts[k][0]=='L') tot[2]+=satts[k];
            if (attempts[k][0]=='R') tot[3]+=satts[k];
        }
        int bd=0;
        for (int k=1;k<4;k++){
            if (tot[k]>tot[bd]) bd=k;
        }
        if (bd==0){
            si--;
            cache.insert(t[si][sj]);
            bestrun.push_back('U');
        }
        if (bd==1){
            si++;
            cache.insert(t[si][sj]);
            bestrun.push_back('D');
        }
        if (bd==2){
            sj--;
            cache.insert(t[si][sj]);
            bestrun.push_back('L');
        }
        if (bd==3){
            sj++;
            cache.insert(t[si][sj]);
            bestrun.push_back('R');
        }
        i=si;
        j=sj;
        stepped=cache;
    }
    for (int k=0;k<bestrun.size();k++){
        cout << bestrun[k];
    }
    cout << endl;
    //cout << s << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//#define SOME_TESTCASE
//#define MOD 998244353LL

#if 1 //テンプレ折り畳み//テンプレ折り畳み//テンプレ折り畳み

#ifdef _DEBUG
#define debug() if(true)
#define dout cout
#define dvout(v) __vout(v)
#define dvvout(v) __vvout(v)
#else
#define debug() if (false)
#define dout if(false)cout
#define dvout(v) if(false)__vout(v)
#define dvvout(v) if(false)__vvout(v)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)//rep
#define repll(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; ++i)//rep
#define repi(i, n1, n) for(int i=n1, i##_len=(n); i<i##_len; ++i)//rep
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)//自然数rep
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)

#define dxout(x) dout<<#x<<":"<<x<<_s//変数デバッグ出力
#define dxoutln(x) dout<<#x<<":"<<x<<_n
#define _Yes {cout<<"Yes"<<endl; return;}//出力
#define _No {cout<<"No"<<endl;return;}
#define _ans {cout<<ans<<endl;return;}
#define _endout(s) {cout<<(s)<<endl;return;}

#define vecvec(v, n, m) vector<vector<int>> v(n, vector<int>(m));
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
#define vin(v) for (auto &i : (v)) cin >> i; //配列入力
#define vvin(v) for(auto&i:(v))for(auto&j:i)cin>>j;
#define __vout(v) {for(auto&i:(v)){cout<<i<<' ';}cout<<"\n";}
#define __vvout(v) {for(auto&i:(v)){for(auto&j:i){cout<<j<<'\t';}cout<<"\n";}cout<<"\n";}

#define INF (INT_MAX/3)
#define INFLL (LLONG_MAX/3)

#ifndef MOD
#define MOD ((ll)(1e9+7))//mod用定数 (ll)(1e9+7)
#endif
#define mod(n) ( ((ll)n) % MOD)
#define modp(n, p) ( ((ll)n) % (ll)(p))
#define modx(A,B) mod(mod(A)*mod(B))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define next asdnext
#define prev asdprev
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"
#define _s " "
#define _output dout<<"output:";
#define _here dout<<"here"<<_n;

void test();

#endif //テンプレ折り畳み

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

vvi visited(52, vi(52,1));
vvi t(52, vi(52, -1));
int p[52][52]={};
ll score=0;
int x,y;

int arrow[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//D,U,R,L
enum{
	D=0,
	U=1,
	R=2,
	L=3
};

void visit(int x, int y){
	visited[x][y]=1;
	score+=p[x][y];
	if(t[x-1][y] == t[x][y])visited[x-1][y]=1;
	else if(t[x+1][y] == t[x][y])visited[x+1][y]=1;
	else if(t[x][y-1] == t[x][y])visited[x][y-1]=1;
	else if(t[x][y+1] == t[x][y])visited[x][y+1]=1;
}

bool visitable(int v){
	return !visited[ (x+arrow[v][0]) ][ (y+arrow[v][1]) ];
}

bool move(int v){
	if(!visitable(v)) return false;



	visit( (x+=arrow[v][0]) , (y+=arrow[v][1]) );
	if(v==0)cout<<'D';
	if(v==1)cout<<'U';
	if(v==2)cout<<'R';
	if(v==3)cout<<'L';
	return true;
}

//solve//solve//solve//solve//solve//solve//solve//solve
void solve(){
	cin>>x>>y;
	x++;y++;

	reps(i,50){
		reps(j,50){
			int c;
			cin>>c;
			t[i][j]=c;
		}
	}
	
	reps(i,50){
		reps(j,50){
			int c;
			cin>>c;
			p[i][j]=c;
		}
	}
	reps(i,50){
		reps(j,50){
			visited[i][j]=0;
		}
	}

	visit(x,y);


	while(1){
		bool flag=0;
		rep(i,4){
			flag|=move(i);
			if(flag)break;
		}
		if(!flag)break;
	}
	cout<<_n;
	dout<<"score"<<score;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(20);
#ifdef SOME_TESTCASE
	int t = 0;
	cin >> t;
	rep(i, t) solve();
#else
	solve();
#endif
	return 0;
}

void test(){
}
