#include<iostream>
#include<stdlib.h>
#include<string>
#include<iomanip>
using namespace std;
int main() {
    int si, sj;
    cin >> si >> sj;
    int t[51][51],p[51][51],i,j,k;
    for (i = 0; i < 50; i++) for (j = 0; j < 50; j++) cin >> t[i][j];
    for (i = 0; i < 50; i++) for (j = 0; j < 50; j++) cin >> p[i][j];
    string idou;
    int idoumax=0,ugoku=0;
    int hikaku[5];
    //動けるところで一番大きいところを探して動く
    while (1) {
        //探す
        for (i = 0; i < 4; i++) {
            //上
            if (i == 0) {
                if (sj - 1 >= 0) {
                    if (t[si][sj] != t[si][sj - 1]) hikaku[0] = p[si][sj - 1];
                    else {
                        hikaku[0] = -1;
                        p[si][sj - 1] = -1;
                    }
                }
                else {
                    hikaku[0] = -1;
                    p[si][sj - 1] = -1;
                }
            }
            //左
            else if (i == 1) {
                if(si-1>=0){
                    if (t[si][sj] != t[si - 1][sj]) hikaku[1] = p[si - 1][sj];
                    else {
                        hikaku[1] = -1;
                        p[si - 1][sj] = -1;
                    }
                }
                else {
                    hikaku[1] = -1;
                    p[si - 1][sj] = -1;
                }
            }
            //下
            else if (i == 2) {
                if(sj+1<=49){
                    if (t[si][sj] != t[si][sj + 1]) hikaku[2] = p[si][sj + 1];
                    else {
                        hikaku[2] = -1;
                        p[si][sj + 1] = -1;
                    }
                }
                else {
                    hikaku[2] = -1;
                    p[si][sj + 1] = -1;
                }
            }
            //右
            else {
                if(si+1<=49){
                    if (t[si][sj] != t[si + 1][sj]) hikaku[3] = p[si + 1][sj];
                    else {
                        hikaku[3] = -1;
                        p[si + 1][sj] = -1;
                    }
                }
                else {
                    hikaku[3] = -1;
                    p[si + 1][sj] = -1;
                }
            }
        }
        idoumax = -1;
        for (int i = 0; i < 4; i++) if (idoumax < hikaku[i]) idoumax = hikaku[i];
        if (idoumax == -1) break;
        for (i = 0; i < 4; i++){
            if (idoumax == hikaku[i]) {
                ugoku = i;
                break;
            }
        }
        //動く
        //上
        if (ugoku == 0) {
            idou += 'L';
            p[si][sj] = -1;
            sj--;
        }
        //左
        else if (ugoku == 1) {
            idou += 'U';
            p[si][sj] = -1;
            si--;
        }
        //下
        else if (ugoku == 2) {
            idou += 'R';
            p[si][sj] = -1;
            sj++;
        }
        //右
        else if (ugoku == 3) {
            idou += 'D';
            p[si][sj] = -1;
            si++;
        }
        else break;
    }
    cout << endl;
    cout << idou << endl;
    return 0;
}
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const double PI = 3.141592653589793238;
int main(){
  auto start = chrono::system_clock::now();
  ll si, sj;
  cin >> si >> sj;
  ll nowi = si, nowj = sj;
  vector<ll> t(2500);
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> t[50 * i + j];
    }
  }

  vector<ll> p(2500);
  for (ll i = 0; i < 50; ++i) for (ll j = 0; j < 50; ++j) cin >> p[50 * i + j];

  string lastans = "";
  ll lastpnt = 0;
  map<ll, bool> used;
  string ans = "";
  while (true) {
    ll id = 50 * nowi + nowj;
    ll maxi = -1;
    used[t[id]] = true;
    char togo = ' ';
    if (nowj != 0 && !used[t[id - 1]] && maxi < p[id - 1]) {
      togo = 'L';
      maxi = p[id - 1];
    }
    if (nowj != 49 && !used[t[id + 1]] && maxi < p[id + 1]) {
      togo = 'R';
      maxi = p[id + 1];
    }
    if (nowi != 0 && !used[t[id - 50]] && maxi < p[id - 50]) {
      togo = 'U';
      maxi = p[id - 50];
    }
    if (nowi != 49 && !used[t[id + 50]] && maxi < p[id + 50]) {
      togo = 'D';
      maxi = p[id + 50];
    }
    if(togo != ' ')ans += togo;
    switch (togo)
    {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    default:
      goto exit;
    }
  }
exit:;
  nowi = si, nowj = sj;
  lastans = ans;
  ll now = 50 * nowi + nowj;
  lastpnt += p[now];
  for (ll i = 0; i < ans.size(); ++i) {
    switch (ans[i]) {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    }
    lastpnt += p[now];
  }

  string sample = "LRUD";
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> cha(0, 3), rand(1,1000);
  auto dur = chrono::system_clock::now() - start;

  double start_temp = 200, end_temp = 10;
  while (chrono::duration_cast<std::chrono::milliseconds>(dur).count() < 1980) {
    ans = lastans;

    uniform_int_distribution<> change(0, ans.size());
    ll ch = change(mt), at = cha(mt), r = rand(mt);
    if (ch == ans.size()) ans.push_back(sample[at]);
    else ans[ch] = sample[at];
    
    nowi = si, nowj = sj;
    now = 50 * nowi + nowj;
    map<ll, bool> used;
    used[t[now]] = true;
    ll pnt = p[now];
    for (ll i = 0; i < ans.size(); ++i) {
      switch (ans[i]) {
      case 'L': --nowj;
        break;
      case 'R': ++nowj;
        break;
      case 'U': --nowi;
        break;
      case 'D': ++nowi;
        break;
      }
      if (nowi < 0 || 49 < nowi || nowj < 0 || 49 < nowj) {
        pnt = -1;
        break;
      }
      now = 50 * nowi + nowj;
      if (used[t[now]]) {
        pnt = -1;
        break;
      }
      used[t[now]] = true;
      pnt += p[now];
    }
    double temp = start_temp + (end_temp - start_temp) * chrono::duration_cast<std::chrono::milliseconds>(dur).count() / 2000;
    double prob = exp((pnt - lastpnt) / temp);

    if (pnt >= lastpnt) {
      lastpnt = pnt;
      lastans = ans;
    }
    else if(pnt != -1 && r <= prob * 1000){
      lastpnt = pnt;
      lastans = ans;
    }
    dur = chrono::system_clock::now() - start;
  }
  cout << lastans << "\n";
}