#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

#define NUM_CAN 20

struct state
{
  int x;
  int y;
  int score;
  string path;
  set<int> used;
};
bool operator< (const state &state1, const state &state2){
    return state1.score < state2.score;
};

int main()
{
  struct timeval tmp_time;
  gettimeofday(&tmp_time, NULL);
  long long program_init_time = tmp_time.tv_sec*1000000+tmp_time.tv_usec;
  long long fin_time, current_time;
  fin_time = program_init_time + 1700000;

  int si, sj, count;
  cin >> si >> sj;
  vector<vector<int>> tiling(50,vector<int>(50)), grids(50,vector<int>(50));
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> tiling.at(i).at(j);
  }
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> grids.at(i).at(j);
  }
  vector<int> dx{1,-1,0,0}, dy{0,0,1,-1};
  string dir = "DURL";
  queue<state> que;
  priority_queue<state> next_que, rest, blank;
  state now_state;
  int best_score;
  string best_path;
  now_state.x = si, now_state.y = sj;
  now_state.score = grids.at(si).at(sj);
  now_state.path = "";
  now_state.used.insert(tiling.at(si).at(sj));
  best_score = now_state.score;
  best_path = now_state.path;
  que.push(now_state);
  count = 0;
  while (!que.empty())
  {
    while (!que.empty())
    {
      count++;
      now_state = que.front();
      que.pop();
      for (int i = 0; i < 4; i++)
      {
        if (now_state.x+dx.at(i) < 0 || now_state.x+dx.at(i) >= 50 || now_state.y+dy.at(i) < 0 || now_state.y+dy.at(i) >= 50)
          continue;
        if (now_state.used.count(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))))
          continue;
        now_state.score += grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
        now_state.path += dir.at(i);
        now_state.used.insert(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)));
        now_state.x += dx.at(i), now_state.y += dy.at(i);
        if (best_score < now_state.score)
        {
          best_score = now_state.score;
          best_path = now_state.path;
        }
        next_que.push(now_state);
        now_state.x -= dx.at(i), now_state.y -= dy.at(i);
        now_state.score -= grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
        now_state.path.pop_back();
        now_state.used.erase(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)));
      }
      if (count % 100 == 0)
      {
        gettimeofday(&tmp_time, NULL);
        current_time = tmp_time.tv_sec*1000000 + tmp_time.tv_usec;
        if (current_time > fin_time)
          break;
      }
    }
    if (count % 100 == 0)
    {
      if (current_time > fin_time)
        break;
    }
    for (int i = 0; i < NUM_CAN; i++)
    {
      if (next_que.empty())
        break;
      que.push(next_que.top());
      next_que.pop();
    }
    while (!next_que.empty())
    {
      rest.push(next_que.top());
      next_que.pop();
    }
    while (que.size() < NUM_CAN && !rest.empty())
    {
      que.push(rest.top());
      rest.pop();
    }
    // next_que = blank;
  }
  cout << best_path << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using P = pair<int,int>;
constexpr int N = 50;
constexpr int Node = 500;
int sx, sy, m = 0;
double start;
int t[50][50];
int p[50][50];
constexpr char dir[4] = {'R','D','L','U'};
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};

// 状態の設定
struct State {
  int score, px, py;
  vector<char> record;
  vector<bool> use; 
  State() {
    score = 0;
    use.assign(m,false);
  }
};

bool operator< (const State& s, const State &t){return s.score < t.score;}
bool operator> (const State& s, const State &t){return s.score > t.score;}

int main(){ 
  // 入力と初期設定
  start = (double)clock();

  cin >> sx >> sy;
  rep(i,N) rep(j,N) {
    cin >> t[i][j];
    m = max(m,t[i][j]);
  }
  m++;
  rep(i,N) rep(j,N) cin >> p[i][j];

  // とりあえずビームサーチ
  State best;
  vector<State> beam_search;
  State is;
  is.px = sx; is.py = sy;
  is.use[t[sx][sy]] = true;
  is.score += p[sx][sy];
  beam_search.push_back(is);
  while(true) {
    if(((double)clock() - start) / CLOCKS_PER_SEC > 1.9) break;
    priority_queue<State,vector<State>,greater<State>> que;
    for(State st : beam_search) {
      int x = st.px, y = st.py;
      rep(i,4) {
        State ns = st;
        int nx = x + dx[i], ny = y + dy[i];
        if(nx < 0 or nx >= N or ny < 0 or ny >= N or ns.use[t[nx][ny]]) continue;
        ns.use[t[nx][ny]] = true;
        ns.px = nx; ns.py = ny;
        ns.score += p[nx][ny];
        ns.record.push_back(i);
        if(que.size() < Node) que.push(ns);
        else if(ns.score > que.top().score) {que.pop(); que.push(ns);}
      }
    }
    beam_search.clear();
    while(que.size()) { 
      beam_search.push_back(que.top());
      que.pop();
    }
    if(beam_search.size() and beam_search.back().score > best.score) best = beam_search.back();
  }
  for(auto x : best.record) cout << dir[x];
  cout << endl;
  return 0;

}