#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 = 1992;

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;
        }
        LL dist = min(nx,abs(h-nx)) + min(ny,abs(w-ny));

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

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

    SORT_DESC(tp);

    for(auto w : tp){
        LL np = w[1];
        LL i = w[2];
        LL nx = w[3];
        LL ny = w[4];
        //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;
}
#include <bits/stdc++.h>
using namespace std;

int si,sj,mx = 0;
int t[55][55],p[55][55];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

bool used[2505];

string base = "RDLU";
string fans = "";

void input() {
    cin >> si >> sj;
    for(int i = 0; i < 50; i++) {
        for(int j = 0; j < 50; j++) {
            cin >> t[i][j];
        }
    }
    for(int i = 0; i < 50; i++) {
        for(int j = 0; j < 50; j++) {
            cin >> p[i][j];
        }
    }
}

int score(string tmp) {
    int nx = si;
    int ny = sj;
    int ans = p[si][sj];
    for(int i = 0; i < tmp.size(); i++) {
        for(int j = 0; j < 4; j++) {
            if(base[j] == tmp[i]) {
                nx += dx[j];
                ny += dy[j];
                ans += p[nx][ny];
            }
        }
    }
    return ans;
}

void chmax(string tmp) {
    if(mx < score(tmp)) {
        mx = score(tmp);
        fans = tmp;
    }
}

string BFS() {
    used[t[si][sj]] = true;
    int nx = si;
    int ny = sj;
    string ans = "";
    int r = rand()%4;
    while (true) {
        bool flag = false;
        if(rand()%25 == 0) {
            r = rand()%4;
        }
        for(int i = r; i < r+4; i++) {
            int nnx = nx+dx[i%4];
            int nny = ny+dy[i%4];
            if(nnx >= 0 && nny >= 0 && nnx < 50 && nny < 50 && !used[t[nnx][nny]]) {
                nx = nnx;
                ny = nny;
                ans += base[i%4];
                flag = true;
                used[t[nnx][nny]] = true;
                break;
            }
        }
        if(!flag) {
            break;
        }
    }
    memset(used,false,sizeof(used));
    return ans;
}

string BFS2(int r) {
    used[t[si][sj]] = true;
    int nx = si;
    int ny = sj;
    string ans = "";
    while (true) {
        bool flag = false;
        for(int i = r; i < r+4; i++) {
            int nnx = nx+dx[i%4];
            int nny = ny+dy[i%4];
            if(nnx >= 0 && nny >= 0 && nnx < 50 && nny < 50 && !used[t[nnx][nny]]) {
                nx = nnx;
                ny = nny;
                ans += base[i%4];
                flag = true;
                used[t[nnx][nny]] = true;
                break;
            }
        }
        if(!flag) {
            break;
        }
    }
    memset(used,false,sizeof(used));
    return ans;
}

int main() {
    srand((unsigned)time(NULL));
    input();
    for(int i = 0; i < 1000000; i++) {
        chmax(BFS());
    }
    chmax(BFS2(0));
    chmax(BFS2(1));
    chmax(BFS2(2));
    chmax(BFS2(3));
    cout << fans << endl;
}
