#include <bits/stdc++.h>
using namespace std;

int main() {
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand4(0, 3);
  
  string D = "UDLR";
  vector<vector<int>> M = {{-1,0},{1,0},{0,-1},{0,1}};
  
  int si, sj;
  cin >> si >> sj;
  
  vector<vector<int>> T(50,vector<int> (50,0));
  vector<vector<int>> P(50,vector<int> (50,0));
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 50; j++) {
      cin >> T[i][j];
    }  
  }
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 50; j++) {
      cin >> P[i][j];
    }  
  }
  
  int MaxScore = 0;
  string MaxMove = {};
  for (int l = 0; l < 10000; l++) {
    vector<vector<int>> C(50,vector<int> (50,1));
    int i = si, j = sj, Score = 0;
    C[i][j] = -1;
    Score += P[i][j];
    string Move = {};
    
    while (true) {
      vector<int> CM(4,1);
      if (i > 0 && T[i][j] == T[i-1][j]) C[i-1][j] = -1;
      if (i == 0 || C[i-1][j] == -1) CM[0] = -1;
      if (i < 49 && T[i][j] == T[i+1][j]) C[i+1][j] = -1;
      if (i == 49 || C[i+1][j] == -1) CM[1] = -1;
      if (j > 0 && T[i][j] == T[i][j-1]) C[i][j-1] = -1;
      if (j == 0 || C[i][j-1] == -1) CM[2] = -1;
      if (j < 49 && T[i][j] == T[i][j+1]) C[i][j+1] = -1;
      if (j == 49 || C[i][j+1] == -1) CM[3] = -1;
      if (CM[0] == -1 && CM[1] == -1 && CM[2] == -1 && CM[3] == -1) break;
      while (true) {
        int k = rand4(mt);
        if (CM[k] == 1) {
          Move = Move + D[k];
          i += M[k][0];
          j += M[k][1];
          C[i][j] = -1;
          Score += P[i][j];
          break;
        }
      }
    }
    if (Score > MaxScore) {
      MaxScore = Score;
      MaxMove = Move;
    }
  }
  
  cout << MaxMove << endl;
  
  return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << p.first << ' ' << p.second;
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

const int c = 50;

string dir = "DRUL";
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};

int si, sj;
V<V<int>> t(c,V<int>(c)), p(c,V<int>(c));


void write_to_text(string ans) {
    ofstream out("AHC002_out.txt");
    out << ans << endl;
    out.close();
}

void print(string ans) {
    cout << ans << endl;
}


string solve() {

    V<bool> seen(c*c);
    string ans = "";

    int y = si, x = sj;
    seen[t[y][x]] = true;

    while(true) {
        P mx = P(-1,-1);
        rep(di,4) {
            int ny = y + dy[di];
            int nx = x + dx[di];
            if(ny < 0 || nx < 0 || ny >= c || nx >= c) continue;
            if(seen[t[ny][nx]]) continue;
            int score;
            if(di == 0) score = (c-ny) * (c-si); // D
            if(di == 1) score = (c-nx) * (c-sj); // R
            if(di == 2) score = ny * si; // U
            if(di == 3) score = nx * sj; // L
            chmax(mx, make_pair(score, di));
            // chmax(mx, make_pair(p[ny][nx], di));
        }
        if(mx == P(-1,-1)) {
            return ans;
        }
        else {
            y += dy[mx.se];
            x += dx[mx.se];
            seen[t[y][x]] = true;
            ans += string(1,mx.se+'0');
        }
    }
}

int calc(string s) {
    int y = si, x = sj;
    int res = 0;
    rep(i,sz(s)) {
        res += p[y][x];
        y += dy[s[i]-'0'];
        x += dx[s[i]-'0'];
    }
    res += p[y][x];
    return res;
}

clock_t start;

pair<int,string> dfs(string s, int y, int x, V<bool> &seen) {
    if(clock() - start > 1980000) return pair<int,string>();
    pair<int,string> res;
    for(int d = 3; d >= 0; d--) {
        int ny = y + dy[d];
        int nx = x + dx[d];
        if(ny < 0 || nx < 0 || ny >= c || nx >= c) continue;
        if(seen[t[ny][nx]]) continue;
        seen[t[ny][nx]] = true;
        chmax(res, dfs(s+string(1,d+'0'), ny, nx, seen));
    }
    if(res.fi == 0) res = make_pair(calc(s),s);
    seen[t[y][x]] = false;
    return res;
}


int main() {
    start = clock();

    cin >> si >> sj;
    cin >> t >> p;
    // string ans = solve();
    V<bool> seen(c*c);
    seen[t[si][sj]] = true;
    auto ans = dfs("",si,sj,seen);
    rep(i,sz(ans.se)) ans.se[i] = dir[ans.se[i]-'0'];
    cout << ans.se << endl;
}