/**
*    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 = 16;
    while(loop--){
        double start = get_time_sec();
        int score = 0;
        string ans = "";
        vector<P> remcell;

        while(get_time_sec() - start<0.124){

            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>

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

// types

int debug;

struct Input {
  int si, sj, num;
  vector<vector<int>> t, p;
  vector<int> sum_score;
  Input(istream &is) : t(50, vector<int>(50)), p(50, vector<int>(50)) {
    is >> si >> sj;
    for (int i = 0; i < 50; ++i)
      for (int j = 0; j < 50; ++j)
        is >> t[i][j];
    for (int i = 0; i < 50; ++i)
      for (int j = 0; j < 50; ++j)
        is >> p[i][j];

    num = 0;
    for (int i = 0; i < 50; ++i)
      for (int j = 0; j < 50; ++j)
        chmax(num, t[i][j] + 1);
    sum_score.resize(num);
    for (int i = 0; i < 50; ++i)
      for (int j = 0; j < 50; ++j)
        sum_score[t[i][j]] += p[i][j];
  }
};

struct Eval {
  int sx, sy;
  int self, other;
};

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const char dir_char[8] = "RDLU";

using Output = pair<string,int>;

Output sub_solve(const Input &input, Eval eval) {
  vector<int> visited(2500);
  int y = input.si, x = input.sj;
  const auto &t = input.t;
  const auto &p = input.p;
  const vector<int> &sum_score = input.sum_score;
  int max_score = 0;
  string max_res = "";

  vector<vector<pair<int,int>>> history;
  vector<int> dir_history;
  int turn = 0;
  int score = p[y][x];
  int max_turn = 0;

  string res = "";
  for (;;) {
    // cout << turn << " " << y << " " << x << endl;
    // if (turn > 10) break;

    int number = t[y][x];
    visited[number] = true;

    if (int(history.size()) <= turn) {
      vector<pair<int,int>> vec;
      for (int dir = 0; dir < 4; ++dir) {
        const int ny = y + dy[dir];
        const int nx = x + dx[dir];
        if (ny < 0 || nx < 0 || ny >= 50 || nx >= 50) continue;
        if (visited[t[ny][nx]]) continue;
        // int score = (nx + ny) * 10 - (sum_score[t[ny][nx]] - p[ny][nx]);
        int score = 0;
        score += nx * eval.sx;
        score += ny + eval.sy;
        score += p[ny][nx] * eval.self;
        score -= (sum_score[t[ny][nx]] - p[ny][nx]) * eval.self;

        vec.emplace_back(score, dir);
      }
      sort(vec.begin(), vec.end());
      history.push_back(vec);
    }
    else if (int(history.size()) > turn + 1) {
      history.pop_back();
    }

    auto &vec = history[turn];
    if (vec.empty()) {
      if (turn < max_turn - 30) break;
      --turn;
      history.pop_back();
      history.back().pop_back();
      const int dir = dir_history.back();
      if (score > max_score) {
        max_score = score;
        max_res = res;
      }
      score -= p[y][x];
      x -= dx[dir];
      y -= dy[dir];
      dir_history.pop_back();
      visited[number] = false;
      res.pop_back();
      continue;
    }

    ++turn;
    chmax(max_turn, turn);
    const int dir = vec.back().second;
    res += dir_char[dir];
    x += dx[dir];
    y += dy[dir];
    score += p[y][x];
    dir_history.push_back(dir);
  }
  return {max_res, max_score};
}

Output solve(const Input &input) {
  int max_score = 0;
  string max_res = "";
  mt19937 mt;
  for (int loop = 0; loop < 100; ++loop) {
    Eval eval;
    eval.sx = mt() % 1000;
    eval.sy = mt() % 1000;
    eval.self = mt() % 1000;
    eval.other = mt() % 1000;
    Output out = sub_solve(input, eval);
    if (out.second > max_score) {
      max_score = out.second;
      max_res = out.first;
    }
  }
  return {max_res, max_score};
}

int main(int argc, char**) {
  debug = (argc > 1);
  if (debug) {
    char filename[256];
    int sum = 0;
    for (int i = 0; i < 100; ++i) {
      sprintf(filename, "in/%.4d.txt", i);
      ifstream ifs(filename);
      Input input(ifs);
      int r = solve(input).second;
      cout << r << endl;
      sum += r;
    }
    cout << sum << endl;
  }
  else {
    const Input input(cin);
    auto res = solve(input);
    cout << res.first << endl;
  }
  return 0;
}
