#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

enum Walk{
	L,R,U,D
};
struct Coord{
	int x,y;
	void move(Walk walk){
		switch(walk){
			case L: y--;
			break;
			case R: y++;
			break;
			case U: x--;
			break;
			case D: x++;
			break;
		}
	}
	void back(Walk walk){
		switch(walk){
			case L: y++;
			break;
			case R: y--;
			break;
			case U: x++;
			break;
			case D: x--;
			break;
		}
	}
};
Coord taka;
struct Grid{
	int val[50][50];
	
	int get(Coord coord){
		return val[coord.x][coord.y];
	}
};
Grid t,p;
vector<bool> visited;
string ans = "";
string lastans;
ll lastscore = 0;
ll numofSearch = 0;
const Walk wlist[4][3] = {
	{L, U, D},
	{R, D, U},
	{U, R, L},
	{D, L, R},
};

system_clock::time_point time_start = system_clock::now();
constexpr double TIME_END = 1950;
random_device seed_gen;
mt19937_64 engine(seed_gen());

void input(){
	scanf("%d %d",&(taka.x),&(taka.y));
	int tmax=0;
	REP(i,50) REP(j,50) {
		scanf("%d" ,&(t.val[i][j]));
		chmax(tmax, t.val[i][j]);
	}
	visited.resize(tmax+1, false);
	REP(i,50) REP(j,50) scanf("%d" ,&(p.val[i][j]));
}
void output(){
	//cerr << "score: " << lastscore << "\nnum: " << numofSearch << "\n";
	// cout << lastans << "\n";
	printf("%s\n",lastans.c_str());
}
void addtoAns(Walk walk){
	switch(walk){
		case L: ans += 'L';
		break;
		case R: ans += 'R';
		break;
		case U: ans += 'U';
		break;
		case D: ans += 'D';
		break;
	}
}
bool canWalk(Walk walk){
	if(walk == L){
		if(taka.y == 0) return false;
		else return !visited[t.val[taka.x][taka.y-1]];
	}
	if(walk == R){
		if(taka.y == 49) return false;
		else return !visited[t.val[taka.x][taka.y+1]];
	}
	if(walk == U){
		if(taka.x == 0) return false;
		else return !visited[t.val[taka.x-1][taka.y]];
	}
	if(walk == D){
		if(taka.x == 49) return false;
		else return !visited[t.val[taka.x+1][taka.y]];
	}
	return false;
}

bool dfs(Walk walk, ll score){
	if(!canWalk(walk)){
		if(score > lastscore){
			lastscore = score;
			lastans = ans;
		}
		return false;
	}
	
	if(numofSearch & (1<<20)){
		auto exe_time = duration_cast<milliseconds>(system_clock::now() - time_start).count();
		if((double)exe_time > TIME_END){
			if(score > lastscore){
				lastscore = score;
				lastans = ans;
			}
			return true;	
		}
	}

	numofSearch++;
	taka.move(walk);
	visited[t.get(taka)] = true;
	score += p.get(taka);
	addtoAns(walk);
	
	if(walk==L){
		for(Walk x: wlist[0]) if(dfs(x, score)) return true;
	}else if(walk==R){
		for(Walk x: wlist[1]) if(dfs(x, score)) return true;
	}else if(walk==U){
		for(Walk x: wlist[2]) if(dfs(x, score)) return true;
	}else if(walk==D){
		for(Walk x: wlist[3]) if(dfs(x, score)) return true;
	}
	
	ans.pop_back();
	visited[t.get(taka)] = false;
	taka.back(walk);
	
	return false;
}

void solve(){
	visited[t.get(taka)] = true;
	
	if(dfs(L,0)) return;
	if(dfs(R,0))  return;
	if(dfs(U,0)) return;
	if(dfs(D,0)) return;
}

int main(){
	input();
	
	solve();
	
	output();
	return 0;
}
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<random>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
ll n=50;
ll dx[] = {1,0,-1,0};
ll dy[] = {0,1,0,-1};
vector<vector<ll>> t(n,vector<ll>(n));
vector<vector<ll>> p(n,vector<ll>(n));
void reset_d(const vector<ll> pt, vector<ll> &used) {
  for(auto p: pt) used[p] = false;
}
bool is_in(ll x,ll y){
  return x>=0&&y>=0&&x<n&&y<n;
}
random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution<int> rand_dist(0, 14);
auto bden = bind(rand_dist, ref(engine));
ll eval(P x){
  return x.first * 300 + x.second;
}
TP prob_search(ll x,ll y,ll time,vector<ll> &used,ll cnt) {
  if (time != 0) {
    used[t[x][y]] = true;
    P now = P(-5,-5);
    ll sid = -1;
    used[t[x][y]] = true;
    for(int i=0;i<4;i++){
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if(!is_in(nx,ny)||used[t[nx][ny]]) {
        continue;
      }
      TP np = prob_search(nx,ny,time-1,used,cnt+1);
      P use = P(get<0>(np)+1,get<1>(np)+p[nx][ny]);
      if (eval(use) > eval(now)) {
        now = use;
        sid = i;
      }
    }
    used[t[x][y]] = false;
    return TP(now.first+1,now.second+p[x][y],sid);
  }
  ll sum = 0;
  vector<ll> use_t;
  ll c = 0;
  while(true){
    ll sid = -1,v=-1;
    used[t[x][y]] = true;
    use_t.push_back(t[x][y]);
    for(int j=0;j<4;j++){
      ll nx = x + dx[j];
      ll ny = y + dy[j];
      if(is_in(nx,ny)&&!used[t[nx][ny]]&&v<p[nx][ny]) {
        v = p[nx][ny];
        sid = j;
      }
    }
    if(sid==-1) {
      reset_d(use_t,used);
      return TP(c, sum,-1);
    }
    sum += v;
    x = x + dx[sid];
    y = y + dy[sid];
    c++;
  }
}
signed main(){
  const string st ="DRUL";
  init_io();
  ll sx,sy;
  cin >> sx >> sy;
  vector<char> mv;
  vector<ll> used(n*n,0);
  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];
    }
  }
  ll x = sx,y = sy;
  while(true){
    auto [sz, score, di] = prob_search(x,y,17,used,0);
    if(di==-1) break;
    used[t[x][y]] = true;
    mv.push_back(st[di]);
    x = x + dx[di];
    y = y + dy[di];
  }
  for(auto c:mv) cout << c;
  cout << endl;
}

