#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}

template <class T>
void chmin(T& a, const T& b) {
  if (b < a) a = b;
}

ll N = 50;
vll a = {-1, 1, 0, 0};
vll b = {0, 0, -1, 1};
vector<char> d = {'U', 'D', 'L', 'R'};
ll si, sj;
vvll tiles(N, vll(N)), points(N, vll(N));
ll tile_count = 0;
ll S = 0;
string ans = "";
vll ans_done;
ll ans_i, ans_j;

void RUN(ll si, ll sj, string st, vll don, ll sc) {
  ll i = si, j = sj;
  vll done = don;
  ll score = sc;
  done[tiles[i][j]] = 1;
  string s = st;
  while (1) {
    vll ikeru;
    rep(k, 4) {
      ll ni = i + a[k];
      ll nj = j + b[k];
      if (ni < 0 or N <= ni or nj < 0 or N <= nj) continue;
      if (done[tiles[ni][nj]] == 1) continue;
      ikeru.pb(k);
    }
    if (ikeru.empty()) break;
    ll r = rand() % ikeru.size();
    ll index = ikeru[r];
    s.pb(d[index]);
    i += a[index];
    j += b[index];
    done[tiles[i][j]] = 1;
    score += points[i][j];
  }
  if (S < score) {
    S = score;
    ans = s;
    ans_done = done;
    ans_i = i;
    ans_j = j;
  }
}

void NOB() {
  ll t_i = ans_i;
  ll t_j = ans_j;
  string t_s = ans;
  vll t_done = ans_done;
  ll t_S = S;
  ll modoru = rand() % t_s.size() + 1 + 20;
  chmin(modoru, (ll)t_s.size());
  rep(r, modoru) {
    char c = t_s[t_s.size() - 1];
    t_s.erase(t_s.end() - 1);
    t_done[tiles[t_i][t_j]] = 0;
    t_S -= points[t_i][t_j];
    if (c == 'U') t_i += 1;
    if (c == 'D') t_i -= 1;
    if (c == 'L') t_j += 1;
    if (c == 'R') t_j -= 1;
  }
  RUN(t_i, t_j, t_s, t_done, t_S);
}

signed main() {
  init();
  cin >> si >> sj >> tiles >> points;
  rep(i, N) chmax(tile_count, MAX(tiles[i]));
  ans_done.resize(tile_count + 1);
  srand(time(NULL));
  rep(n, 1000) RUN(si, sj, "", vll(tile_count + 1), points[si][sj]);
  rep(n, 390000) NOB();
  debug(S);
  ANS;
  return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

struct Tile {
	int tileNum;
	int point;
};

int si, sj;
Tile tile[52][52];
string ans;
string finalans;
bool used[2500];
int di[4] = { -1,0,0,1 };
int dj[4] = { 0,1,-1,0 };
vector<pair<int,int>> moveij;

void move(int ni, int nj, int nowij) {
	if (ni == 51 || nj == 51 || ans.empty()&&(ni!=si&&nj!=sj)) 
		return;
	moveij.push_back(pair<int, int>(ni, nj));
	tile[50][50].point = -1;
	used[tile[ni][nj].tileNum] = true;
	/*
	if ((tile[ni - 1][nj].used || tile[ni][nj].tileNum == tile[ni - 1][nj].tileNum) ||
		(tile[ni + 1][nj].used || tile[ni][nj].tileNum == tile[ni + 1][nj].tileNum) ||
		(tile[ni][nj - 1].used || tile[ni][nj].tileNum == tile[ni][nj - 1].tileNum) ||
		(tile[ni][nj + 1].used || tile[ni][nj].tileNum == tile[ni][nj + 1].tileNum)) {//どこにもいけない
		return;
	}
	*/
	int nexti = 51, nextj = 51;
	for (int i = 0; i < 4; i++) {
		if (0 <= ni + di[i] && ni + di[i] < 50 && 0 <= nj + dj[i] && nj + dj[i] < 50){
			if (!used[tile[ni + di[i]][nj + dj[i]].tileNum]) {
				if (tile[ni + di[i]][nj + dj[i]].point > tile[nexti][nextj].point) {
					nexti = ni + di[i]; nextj = nj + dj[i];
				}
			}
		}
	}
	if (nexti == 51 && nextj == 51) {
		//string change;
		finalans = (finalans.size() > ans.size()) ? finalans : ans;
		//finalans.erase(0);
		//finalans = change;
		ans.erase((int)ans.size() - 1);
		if (moveij.size() <= 1)return;
		moveij.erase(moveij.end()-1);
		--nowij;
		if (nowij <= 0) 
			return;
		int nni = moveij[nowij].first;
		int nnj = moveij[nowij].second;
		moveij.erase(moveij.end() - 1);
		move(nni, nnj, nowij);
	}
	else {
		if (nexti == ni - 1) ans.push_back('U');
		else if (nexti == ni + 1)ans.push_back('D');
		else if (nextj == nj - 1)ans.push_back('L');
		else if (nextj == nj + 1)ans.push_back('R');
		move(nexti, nextj, ++nowij);
	}
}

int main() {
	cin >> si >> sj;
	rep(i, 50) rep(j, 50) cin >> tile[i][j].tileNum;
	rep(i, 50) rep(j, 50) cin >> tile[i][j].point;
	move(si, sj, 0);
	cout << finalans << endl;
	return 0;
}