#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
//using vi = vector<int>;

int start_time;
int si, sj;
int highscore;
string best_S = "";
vector<vector<int>> t(50, vector<int>(50));
vector<vector<int>> p(50, vector<int>(50));
vector<int> near_i = {1,-1,0,0};
vector<int> near_j = {0,0,1,-1};
vector<char> near = {'D','U','R','L'};

void dfs(int pi, int pj, int score, string &S, vector<bool> &used){
    if(clock() - start_time > 190 * CLOCKS_PER_SEC / 100){
        return;
    }

    if(used.at(t.at(pi).at(pj))){
        return;
    }
    used.at(t.at(pi).at(pj)) = true;
    score += p.at(pi).at(pj);

    if(score > highscore){
        best_S = S;
        highscore = score;
    }

    rep(i, 4){
        if(pi + near_i.at(i) >= 50 || pi + near_i.at(i) < 0 ||  pj + near_j.at(i) >= 50 ||  pj + near_j.at(i) < 0){
            continue;
        }
        S += near.at(i);
        dfs(pi + near_i.at(i), pj + near_j.at(i), score, S, used);
        S.erase(S.size()-1);
    }
    score -= p.at(pi).at(pj);
    used.at(t.at(pi).at(pj)) = false;

}


int main(){
    cin>>si>>sj;
    rep(i,50)rep(j,50){
        cin >> t.at(i).at(j);
    }
    rep(i,50)rep(j,50){
        cin >> p.at(i).at(j);
    }

    start_time = clock();

    vector<bool> used(2500, false); 
    string empty_S;
    dfs(si,sj,0,empty_S,used);
    //cout << start_time << endl;
    cout << best_S << endl;
  
}
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i, n) for(int i = 0; i < n;++i)
#define reps(i, s, n) for(int i = s; i < n;++i)
const int MAX_W = 50, MAX_H = 50;

int dx[4] = {+1,0,-1,0};
int dy[4] = {0,+1,0,-1};
char dm[4] = {'R', 'D', 'L', 'U'};

vvi v(MAX_H, vi(MAX_W, 0)), T(MAX_H, vi(MAX_W, 0)), P(MAX_H, vi(MAX_W, 0));

int f_w(int sx, int sy){
  int allS=P[sy][sx];
  v[sy][sx] = 1;
  rep(i,4){
    int ssx = sx + dx[i], ssy = sy + dy[i];
    if(ssx>=0 && ssx<MAX_W && ssy>=0 && ssy<MAX_H && T[sy][sx]==T[ssy][ssx]) v[ssy][ssx]=1;
  }
  queue<pair<int,int>> Q;
  Q.push(make_pair(sx, sy));
  while(!Q.empty()){
  	int px = Q.front().first, py = Q.front().second;
    Q.pop();
    v[py][px] = 1;
    allS += P[py][px];
    rep(i,4){
      int ppx = px + dx[i], ppy = py + dy[i];
      if(ppx>=0 && ppx<MAX_W && ppy>=0 && ppy<MAX_H && T[py][px]==T[ppy][ppx]) v[ppy][ppx]=1;
    }
    int tx = px, ty = py, s=0, w=-1;
    rep(i,4){
      int ttx = px + dx[i], tty = py + dy[i];
      if(ttx>=0 && ttx<MAX_W && tty>=0 && tty<MAX_H && v[tty][ttx]==0){
        if(s<P[tty][ttx]){
            s = P[tty][ttx];
            tx = ttx;
            ty = tty;
            w = i;
        }
      }
    }
    if(s>0){
        Q.push(make_pair(tx, ty));
        cout<< dm[w];
    }
  }
  return allS;
}


int main() {
    int si, sj;
    cin >> si >> sj;
    rep(i, MAX_H)rep(j, MAX_W) cin >> T[i][j];
    rep(i, MAX_H)rep(j, MAX_W) cin >> P[i][j];
    f_w(sj, si);
}
