/**
 * @file:           A.cpp
 * @author:         yaoxi-std
 * @description:    A.cpp
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define resetIO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
#define testcases int T; read(T); while(T --)
#define debug(fmt, ...) fprintf(stderr, "[%s:%d] " fmt, __FILE__, __LINE__, ## __VA_ARGS__)
#define debug_var(var) cerr << #var" = " << var << endl
#define debug_arr(arr, n) cerr << #arr" = ["; for(int _i=1; _i<=n; _i++) \
        cerr << arr[_i] << (_i == n ? "]\n" : ", ")
#define debug_vec(vec) cerr << #vec" = ["; for(int _i=0; _i<vec.size(); _i++) \
        cerr << vec[_i] << (_i == vec.size() - 1 ? "]\n" : ", ")
template<class T> inline void read(T &x){
    T f = 1; x = 0; char ch = getchar();
    for( ; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -f;
    for( ; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= f;
}
template<class T> inline void write(T x){
    if(x < 0) { putchar('-'); x = -x; }
    if(x > 9) write(x / 10); putchar((x % 10) ^ 48);
}
const int maxn = 1005;
const int maxm = 1e5+5;
const int inf = 1LL << 60;
const int ddx[4] = { -1, 0, 1, 0 };
const int ddy[4] = { 0, -1, 0, 1 };
const char dchr[4] = { 'U', 'L', 'D', 'R' };
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };
char chr[4] = { 'U', 'L', 'D', 'R' };
int n, sx, sy, t[maxn][maxn], p[maxn][maxn], mx, mxstp, cnt;
int ord[maxm];
char mxord[maxm];
bool vis[maxm];
bool dfs(int x, int y, int sc, int stp){
    ++ cnt;
    if(stp > 1000) return false;
    if(sc > mx){
        mx = sc; mxstp = stp;
        for(int i=1; i<stp; i++) mxord[i] = chr[ord[i]];
    }
    if(cnt > 4000000) return true;
    for(int i=0; i<4; i++){
        int tx = x + dx[i];
        int ty = y + dy[i];
        if(tx < 1 || ty < 1 || tx > n || ty > n) continue;
        if(vis[t[tx][ty]]) continue;
        vis[t[tx][ty]] = true;
        ord[stp] = i;
        if(dfs(tx, ty, sc + p[tx][ty], stp + 1)){
            vis[t[tx][ty]] = false;
            return true;
        } 
        vis[t[tx][ty]] = false;
    }
    return false;
}
signed main(){
    n = 50;
    read(sx); read(sy); sx ++; sy ++;
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(t[i][j]);
    for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) read(p[i][j]);
    vis[t[sx][sy]] = true;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                for(int l=0; l<4; l++){
                    if(i == j || j == k || k == l ||
                       i == k || i == l || j == l) continue;
                    dx[0] = ddx[i]; dy[0] = ddy[i]; chr[0] = dchr[i];
                    dx[1] = ddx[j]; dy[1] = ddy[j]; chr[1] = dchr[j];
                    dx[2] = ddx[k]; dy[2] = ddy[k]; chr[2] = dchr[k];
                    dx[3] = ddx[l]; dy[3] = ddy[l]; chr[3] = dchr[l];
                    memset(vis, false, sizeof(vis)); cnt = 0;
                    vis[t[sx][sy]] = true;
                    dfs(sx, sy, 0, 1);
                }
            }
        }
    }
    for(int i=1; i<mxstp; i++) putchar(mxord[i]);
    putchar('\n');
    return 0;
}
#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }

//==================param==========
ll depth = 10;
//=================================

ll si, sj;
vector<vector<ll>> board(50, vector<ll>(50));
vector<vector<ll>> point(50, vector<ll>(50));
map<ll, bool> already;
vector<char> way_char = {'R', 'D', 'L', 'U'};
vector<vector<ll>> ways = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
stack<ll> max_ans;
stack<ll> ans;
stack<ll> est;
ll max_point = 0;
ll now_point = 0;
clock_t start;
mt19937 mt{random_device{}()};
uniform_int_distribution<int> dist(0, 3);
uniform_int_distribution<int> choose_way(0, 23);

vector<vector<ll>> all_ways;

void get_input() {
  cin >> si >> sj;
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> board.at(i).at(j);
    }
  }
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> point.at(i).at(j);
    }
  }
  already[board.at(si).at(sj)] = true;

  for (ll i = 0; i < 4; ++i) {
    for (ll j = 0; j < 4; ++j) {
      for (ll k = 0; k < 4; ++k) {
        for (ll l = 0; l < 4; ++l) {
          set<ll> temp_st;
          temp_st.insert(i);
          temp_st.insert(j);
          temp_st.insert(k);
          temp_st.insert(l);
          if (temp_st.size() != 4) {
            continue;
          }
          all_ways.push_back({i, j, k, l});
        }
      }
    }
  }
}

bool can_move(ll way) {
  ll nh = si + ways.at(way).at(0), nw = sj + ways.at(way).at(1);
  if (nh < 0 || nw < 0 || nh >= 50 || nw >= 50) {
    return false;
  }
  if (already[board.at(nh).at(nw)]) {
    return false;
  }
  return true;
}

void make_move(ll way) {
  si += ways.at(way).at(0), sj += ways.at(way).at(1);
  already[board.at(si).at(sj)] = true;
  ans.push(way);
  now_point += point.at(si).at(sj);
  if (now_point > max_point) {
    max_ans = ans;
    max_point = now_point;
  }
}
void rev_move() {
  ll way = ans.top();
  ans.pop();
  now_point -= point.at(si).at(sj);
  already[board.at(si).at(sj)] = false;
  si -= ways.at(way).at(0), sj -= ways.at(way).at(1);
}

ll cnt = 0;
bool fin = false;
ll last = 0;
vector<ll> now_ways;
void dfs() {
  if (fin) {
    return;
  }
  cnt += 1;
  if (cnt % 1000 == 0) {
    clock_t end = clock();
    ld time = (ld)(end - start) / CLOCKS_PER_SEC * 1000.0;
    if (time > 1900 || time - last >= 100) {
      fin = true;
      last = time;
      return;
    }
  }
  for (ll i = 0; i < 4; ++i) {
    ll w = now_ways.at(i);
    if (can_move(w)) {
      make_move(w);
      dfs();
      rev_move();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  start = clock();
  get_input();
  while (true) {
    now_ways = all_ways.at(choose_way(mt));
    dfs();
    if (last > 1900) {
      break;
    }
    uniform_int_distribution<int> temp(max(0ll, (ll)ans.size() - 5), (ll)ans.size());
    for (ll i = 0; i < temp(mt); ++i) {
      rev_move();
    }
    // ans = est;
    // now_point = 0;
    fin = false;
  }
  string s_ans = "";
  while (!max_ans.empty()) {
    s_ans += way_char.at(max_ans.top());
    max_ans.pop();
  }
  reverse(rng(s_ans));
  cout << s_ans << "\n";
}
