#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int q[50][50];int u[50][50];int v[2501];vector<int> s;vector<int> ms;int mt=-1;int tt=0;
time_point<high_resolution_clock> start;
#pragma GCC optimize("O2")
char h(int c){
	if(c==0)return 'D';
	if(c==1)return 'R';
	if(c==2)return 'U';
	return 'L';
}
void bk(int x,int y,int t){
	tt++;
	if(tt>43000000){
		auto stop=high_resolution_clock::now();
		auto duration=duration_cast<milliseconds>(stop-start);
		if(duration.count()>1990)return;
	}
	v[u[x][y]]=1;
	if(t>mt){ms=s;mt=t;}
	for(int i=0;i<=3;i++){
		int a,b;
		if(i==0){a=x+1;b=y;}
		else if(i==1){a=x;b=y+1;}
		else if(i==2){a=x-1;b=y;}
		else {a=x;b=y-1;}
		if((min(a,b)>=0&&max(a,b)<=49&&v[u[a][b]]==0)){
		s.push_back(i);
		bk(a,b,t+q[x][y]);
		s.pop_back();
	}}
	v[u[x][y]]=0;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int x,y;cin>>x>>y;int c=0;
	for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>u[i][j];
	for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>q[i][j];
	start=high_resolution_clock::now();
	v[u[x][y]]=1;
	bk(x,y,q[x][y]);
	/*while(1){
		vector<pair<int,int>> o;
		for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4});
		sort(o.rbegin(),o.rend());
		for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk1;}}
		break;sk1:continue;
	}
	while(1){
		vector<pair<int,int>> o;
		for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4});
		sort(o.rbegin(),o.rend());
		for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk2;}}
		break;sk2:continue;
	}*/
	for(auto i:ms)cout<<h(i);
	/*while(1){
		vector<pair<int,int>> o;
		for(int i=0;i<=3;i++)o.push_back({l(x,y,(c+i)%4,1),(c+i)%4});
		sort(o.rbegin(),o.rend());
		for(auto i:o){if(f(x,y,i.second,1)&&f(x,y,i.second,2)&&f(x,y,i.second,3)){auto p=w(x,y,i.second,1);x=p.first;y=p.second;c=i.second;cout<<h(c);goto sk3;}}
		break;sk3:continue;
	}*/
	cout<<endl;//cout<<tt<<endl;
  return 0;
}

#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, 1){
		
		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();
}