#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#include <chrono>
#include <ctime>
#include <random>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
using namespace chrono;
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(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();

int si,sj;
vvi t;
vvi p;

// そのマスを使ったか？
vvi flag_mass;
// そのタイル番号を使ったか？
vi flag_tile;

vi dx = {0, 1, 0, -1};
vi dy = {1, 0, -1, 0};
map<int,char> mp = {{0, 'R'}, {1, 'D'}, {2, 'L'}, {3, 'U'}};

void Input() {
  cin >> si >> sj;
  t.assign(50, vi(50));
  p.assign(50, vi(50));
  rep(i,50) {
    rep(j,50) {
      cin >> t[i][j];
    }
  }
  rep(i,50) {
    rep(j,50) {
      cin >> p[i][j];
    }
  }  
}

string res;
string keiro;
int max_point = 0;
int point = 0;
auto startClock = system_clock::now();
int step = 0;
double END_TIME = 1.95;
vi junban = {0, 1, 2, 3};
int num;
double X = 1./8.;
int bot = 0;
int flag = 0;

void Dfs(int x, int y) {
  point += p[x][y];
  if(chmax(max_point, point)) {
    res = keiro;
    num = bot;
  }      
  flag_tile[t[x][y]] = 1;
  step++;
  if(step % 1000 == 0) {
    double time = duration_cast<microseconds>(system_clock::now() - startClock).count() * 1e-6;   
    if(time >= END_TIME * X) {
      if(flag) {
        cout << res << "\n";
        exit(0);
      }
      flag_tile.assign(2501, 0);
      keiro.clear();
      point = 0;
      X += 1./8.;
      bot++;
      if(bot == 4) {
        X = 1;
        bot = num;
        flag = 1;
      }
      Dfs(si, sj);
    }
  }
  // random_device seed_gen;
  // mt19937 engine(seed_gen());
  // shuffle(junban.begin(), junban.end(), engine);  
  rep(i,4) {
    int j = (i+bot) % 4;
    int nx = x + dx[j], ny = y + dy[j];
    if(0 <= nx && nx < 50 && 0 <= ny && ny < 50) {
      int t_num = t[nx][ny];
      if(flag_tile[t_num]) continue;
      keiro.push_back(mp[j]);
      Dfs(nx, ny);
      keiro.pop_back();
    }
  }
  point -= p[x][y];
  flag_tile[t[x][y]] = 0;
}

void Solve() {
  flag_tile.assign(2501, 0);
  startClock = system_clock::now();
  Dfs(si, sj);
}

int main()
{
  Input();  
  Solve();
  return 0;
}


/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}
();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
//#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vvb= vector<vb>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

const int N=50;
const vi di= { -1, 1, 0, 0};
const vi dj= { 0, 0, -1, 1};
const vector<char> dc= { 'U', 'D', 'L', 'R' };

vvb vis0(N, vb(N)); /* direct vis */
vvb vis1(N, vb(N)); /* also vis */
vvi t(N, vi(N));
vvi p(N, vi(N));

inline void alsoset(int i, int j) {
    for(int k=0; k<4; k++) {
        const int ii=i+di[k];
        const int jj=j+dj[k];
        if(ii>=0 && ii<N && jj>=0 && jj<N && t[i][j]==t[ii][jj]) {
            vis1[ii][jj]=vis0[i][j];
            break;
        }
    }
};

const int T=2e7;
int cnt=0;
ll ans=0;      /* best answer so far */
string apath;   /* path of best answer */

ll sum=0;      /* sum in current path */
string path;    /* current path */


void go(int i, int j) {
    if(cnt++>T)
        return;

    //assert(!vis0[i][j] && !vis1[i][j]);
    vis0[i][j]=true;
    alsoset(i,j);
    sum+=p[i][j];
    if(sum>ans) {
        ans=sum;
        apath=path;
    }

    using t3=tuple<int,int,int>;
    vector<t3> next;
    for(int d=0; d<4; d++) {
        const int ii=i+di[d];
        const int jj=j+dj[d];
        if(ii>=0 && ii<N && jj>=0 && jj<N && !vis0[ii][jj] && !vis1[ii][jj]) {
            next.emplace_back(ii,jj,d);
        }
    }

    /* Now sort the next steps by some criteria.
     * 1. Use a simple heuristic where we want to stay on
     * maximize the distance between the middle of the map and the
     * borders.
     */
    sort(all(next), [](t3 &p1, t3 &p2) {
        auto [p1x,p1y,p1d]=p1;
        auto [p2x,p2y,p2d]=p2;

        /* dist from center quad */
        const int dc1=abs(N/2-p1x)*abs(N/2-p1x)+abs(N/2-p1y)*abs(N/2-p1y);
        const int dc2=abs(N/2-p2x)*abs(N/2-p2x)+abs(N/2-p2y)*abs(N/2-p2y);

        /* dist from border quad */
        const int x1=min(p1x, N-p1x);
        const int y1=min(p1y, N-p1y);
        const int d1=min(dc1, min(x1,y1)*min(x1,y1));

        const int x2=min(p2x, N-p2x);
        const int y2=min(p2y, N-p2y);
        const int d2=min(dc2, min(x2,y2)*min(x2,y2));

        /* maximize both distances */
        return d1 > d2;
    });

    for(auto [iii,jjj,ddd] : next) {
        path+=dc[ddd];
        go(iii,jjj);
        path.pop_back();
    }

    vis0[i][j]=false;
    alsoset(i,j);
    sum-=p[i][j];
};

/* There is a more or less simple brute force,
 * first implement that.
 */
void solve() {
    cini(si);
    cini(sj);

    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin>>t[i][j];

    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin>>p[i][j];

    go(si,sj);

    cerr<<ans<<endl;
    cout<<apath<<endl;

}

signed main() {
    solve();
}