#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#include <cassert>
#include <fstream>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
#define y first
#define x second
constexpr bool istest = false;
constexpr int n = 50;
ifstream file;
ofstream out;
void input_setup(){
	if(istest){
		cout << "write the in file number\n";
		string s;
		cin >> s;
		file.open("C:/Users/souta/downloads/ahc/tools/in/" + s + ".txt");
		if(file.fail()){
			cout << "the file was not found\n";
			return;
		}
		cin.rdbuf(file.rdbuf());
	}
}
//答えるときのやつ
string ans = "";
void output(){
	if(istest){
		out.open("C:/users/souta/downloads/ahc/tools/out.txt");
		if(out.fail()){
			cout << "the file was not found\n";
			return;
		}
		cout.rdbuf(out.rdbuf());
	}
	cout << ans << "\n";
}
pii st_pos;
vvi tiles(n, vi(n)), point(n, vi(n));
void inputs(){
	//start position
	cin >> st_pos.y >> st_pos.x;
	//tiles
	rep(i, n) rep(j, n) cin >> tiles[i][j];
	//points
	rep(i, n) rep(j, n) cin >> point[i][j];
}

//過去に同じ番号のタイルを通ったことがあるのかを確認する
bool checkVisited(const int &Y, const int &X, const vector<pii> &logs){
	int col = tiles[Y][X];
	for(auto a : logs){
		if(col == tiles[a.y][a.x]) return true;
	}
	return false;
}
//とりあえずBFSで探索してみる
int dy[] = {-1,1,0,0};
int dx[] = {0,0,-1,1};
char dir[] = {'U', 'D', 'L', 'R'};
void bfs(){
	priority_queue<pair<pii, int>> que;
	vvi checked(n, vi(n, -1));
	checked[st_pos.y][st_pos.x] = point[st_pos.y][st_pos.x];
	vector<vector<vector<pii>>> logs(n, vector<vector<pii>>(n));

	logs[st_pos.y][st_pos.x].push_back(make_pair(st_pos.y, st_pos.x));

	pii bestpos = st_pos;
	int mx = point[st_pos.y][st_pos.x];

	rep(loop, 10){
		
		vector<pii> temp = logs[bestpos.y][bestpos.x];
		logs = vector<vector<vector<pii>>>(n, vector<vector<pii>>(n));
		checked = vvi(n, vi(n, -1));
		logs[bestpos.y][bestpos.x] = temp;
		checked[bestpos.y][bestpos.x] = mx;
		que.push(make_pair(bestpos, mx));
		
		while(!que.empty()){
			pii pos; int score;
			tie(pos, score) = que.top();
			que.pop();
			if(checked[pos.y][pos.x] > score) continue;
			rep(i, 4){
				int Y = pos.y + dy[i];
				int X = pos.x + dx[i];
				if(Y >= n || X >= n || Y < 0 || X < 0) continue;
				if(checkVisited(Y, X, logs[pos.y][pos.x])) continue;

				int v = score + point[Y][X];
				if(checked[Y][X] == -1 || checked[Y][X] < v){
					que.push(make_pair(make_pair(Y, X), v));
					checked[Y][X] = v;
					logs[Y][X] = logs[pos.y][pos.x];
					logs[Y][X].push_back(make_pair(Y, X));
				}
			}
		}

		mx = 0;
		bestpos = st_pos;
		rep(i, n) rep(j, n){
			if(mx < checked[i][j]){
				bestpos = make_pair(i, j);
				mx = checked[i][j];
			}
		}
	}

	vector<pii> track = logs[bestpos.y][bestpos.x];
	pii last = st_pos;
	for(auto a : track){
		rep(i, 4){
			if(last.y + dy[i] == a.y && last.x + dx[i] == a.x){
				ans += dir[i];
				break;
			}
		}
		last = a;
	}
}
int main(){
	input_setup();
	inputs();

	bfs();

	output();
}
#include <bits/stdc++.h>
using namespace std;

void used_tile(vector<vector<int> > &t,int x,int y)
{
  if(t[x][y]==t[x-1][y]) t[x-1][y]=-1;
  else if(t[x][y]==t[x+1][y]) t[x+1][y]=-1;
  else if(t[x][y]==t[x][y-1]) t[x][y-1]=-1;
  else if(t[x][y]==t[x][y+1]) t[x][y+1]=-1;
  t[x][y]=-1;
}
int cant_move(vector<vector<int> > t,int x,int y)
{
  if(t[x-1][y]==-1&&t[x+1][y]==-1&&t[x][y-1]==-1&&t[x][y+1]==-1) return 1;
  else return 0;
}
void can_move(vector<vector<int> > t,int x,int y,vector<int> &can)
{
  if(t[x-1][y]!=-1) can[2]=1;
  if(t[x+1][y]!=-1) can[3]=1;
  if(t[x][y-1]!=-1) can[0]=1;
  if(t[x][y+1]!=-1) can[1]=1;
}
void random(int &x,int &y,vector<int> can,vector<string> &answer){
  int select=rand()%can.size();
  if(select==0&&can[select]==1) {y=y-1; answer.push_back("L");}
  else if(select==1&&can[select]==1) {y=y+1;answer.push_back("R");}
  else if(select==2&&can[select]==1) {x=x-1;answer.push_back("U");}
  else if(select==3&&can[select]==1) {x=x+1;answer.push_back("D");}
}
void to_right(int &x,int &y,vector<int> can,vector<string> &answer)
{
  if(can[1]==1) {y=y+1;answer.push_back("R");}
  else if(can[3]==1) {x=x+1;answer.push_back("D");}
  else if(can[2]==1) {x=x-1;answer.push_back("U");}
  else if(can[0]==1) {y=y-1;answer.push_back("L");}
}
void circle(int &x,int &y,vector<int> can,vector<string> &answer,int &type)
{
  if(type==1){
    if(x>35) type=2;
    if(can[3]==1){x=x+1;answer.push_back("D");}
    else if(can[1]==1) {y=y+1;answer.push_back("R");}
    else if(can[0]==1) {y=y-1;answer.push_back("L");}
    else if(can[2]==1) {x=x-1;answer.push_back("U");}
  }
  else if(type==2){
    if(y>35) type=3;
    if(can[1]==1) {y=y+1;answer.push_back("R");}
    else if(can[3]==1) {x=x+1;answer.push_back("D");}
    else if(can[2]==1) {x=x-1;answer.push_back("U");}
    else if(can[0]==1) {y=y-1;answer.push_back("L");}
  }
  else if(type==3){
    if(x<15) type=4;
    if(can[2]==1){x=x-1;answer.push_back("U");}
    else if(can[1]==1) {y=y+1;answer.push_back("R");}
    else if(can[0]==1) {y=y-1;answer.push_back("L");}
    else if(can[3]==1) {x=x+1;answer.push_back("D");}
  }
  else if(type==4){
    if(y<15) type=1;
    if(can[0]==1) {y=y-1;answer.push_back("L");}
    else if(can[3]==1) {x=x+1;answer.push_back("D");}
    else if(can[2]==1) {x=x-1;answer.push_back("U");}
    else if(can[1]==1) {y=y+1;answer.push_back("R");}
  }
}
int main()
{
  vector<string> answer;
  vector<vector<int> > t(52,vector<int>(52));
  vector<vector<int> > p(52,vector<int>(52));
  int si,sj;
  cin>>si>>sj;
  si=si+1;
  sj=sj+1;
  for(int i=1;i<51;i++){
    for(int j=1;j<51;j++) cin>>t[i][j];
  }
  for(int i=1;i<51;i++){
    for(int j=1;j<51;j++) cin>>p[i][j];
  }
  for(int i=0;i<52;i++){
    t[0][i]=-1;
    t[51][i]=-1;
    t[i][0]=-1;
    t[i][51]=-1;
  }

  used_tile(t,si,sj);
  int flag=0;
  int type=1;
  while(flag==0){
    vector<int> can(4,0);
    can_move(t,si,sj,can);
    circle(si,sj,can,answer,type);
    used_tile(t,si,sj);
    flag=cant_move(t,si,sj);
  }
  for(int i=0;i<answer.size();i++) cout<<answer[i];
  cout<<endl;
}
