#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll startTime;
const int Di[] = {-1,+1, 0, 0};
const int Dj[] = { 0, 0,-1,+1};
long long getTime() {
	timespec ts;
	clock_gettime(CLOCK_REALTIME_COARSE, &ts);
	long long r = ts.tv_sec;
	r *= 1000000000;
	r += ts.tv_nsec;
	return r;
}
struct Input {
	int Si, Sj;
	vector<vector<int>> T, P;
	Input() : T(50, vector<int>(50)), P(50, vector<int>(50)) {
		cin >> Si >> Sj;
		for (auto& a : T) for (auto& x : a) cin >> x;
		for (auto& a : P) for (auto& x : a) cin >> x;
	}
};
struct State {
	vector<bool> visited;
	int i, j, score;
	State(){}
	State(int M, int i, int j, int score) : visited(M), i(i), j(j), score(score) {}
};
struct Solver {
	const Input& X;
	mt19937 mt;
	int M;
	pair<int,int> best0;
	int cnt_best0;
	pair<int,pair<int,int>> best1;
	Solver(const Input& x) : X(x) {
		random_device seed_gen;
		mt = mt19937(seed_gen());
	}
	int rnd(int n) {
		return uniform_int_distribution<>(0,n-1)(mt);
	}
	bool valid(const State& s, int d) {
		int i = s.i + Di[d];
		int j = s.j + Dj[d];
		return 0 <= i && i < 50 && 0 <= j && j < 50 && !s.visited[X.T[i][j]];
	}
	void move(State& s, int d) {
		s.i += Di[d];
		s.j += Dj[d];
		s.visited[X.T[s.i][s.j]] = true;
		s.score += X.P[s.i][s.j];
	}
	void f(int p, int q, int prev, const State& s) {
		if (p == 15) {
			if (s.score > best0.first) {
				best0 = {s.score, q};
				cnt_best0 = 1;
			} else if (s.score == best0.first) {
				if (rnd(++ cnt_best0) == 0) {
					best0 = {s.score, q};
				}
			}
			return;
		} else {
			best1 = max(best1, {s.score, {p, q}});
		}
		for (int d = 0; d < 4; ++ d) if ((d^1) != prev && valid(s, d)) {
			State ss = s;
			move(ss, d);
			f(p+1, q | (d << (2*p)), d, ss);
		}
	}
	void solve() {
		M = 0;
		for (auto& a : X.T) for (auto& x : a) M = max(M, x+1);

		int best_score = -1;
		vector<int> best_res;

		{
			State s0(M, X.Si, X.Sj, X.P[X.Si][X.Sj]);
			s0.visited[X.T[X.Si][X.Sj]] = true;
			vector<int> res;
			for (;;) {
				best0 = {-1, 0};
				best1 = {-1, {0, 0}};
				f(0, 0, -1, s0);
				if (best1.first > best_score) {
					best_score = best1.first;
					auto rr = res;
					for (int i = 0; i < best1.second.first; ++ i) {
						int d = (best1.second.second >> (2*i)) & 3;
						rr.push_back(d);
					}
					best_res = rr;
				}
				if (best0.first == -1) {
					break;
				} else {
					int d = best0.second & 3;
					res.push_back(d);
					move(s0, d);
				}
			}
		}

		cerr << "score = " << best_score << endl;
		for (auto x : best_res) cout << "UDLR"[x];
		cout << endl;
	}
};
int main() {
	startTime = getTime();
	Input x;
	Solver y(x);
	y.solve();
}

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int t[55][55];
int p[55][55];
bool bo[2600] = { false };
int b1[4];
int b2[4];
int b3[4] = { 1,-1,0,0 };
int b4[4] = { 0,0,1,-1 };
int b5[4] = { 0,1,2,3 };
int main() {
	int x, y;
	cin >> x >> y;
	stack<pair<int, int>> s;
	s.push(make_pair(x, y));
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> t[i][j];
		}
	}
	bo[t[x][y]] = true;
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> p[i][j];
		}
	}
	string ans = "";
	int score = -1000000007;
	vector<pair<int, int>> vec;
	bool bo2[2600];
	do {
		for (int i = 0; i < 4; i++) {
			b1[i] = b3[b5[i]];
			b2[i] = b4[b5[i]];
		}
		string ans1 = "";
		int score1 = 0;
		vector<pair<int, int>> vec1;
		while (1) {
			int nx = s.top().first;
			int ny = s.top().second;
			bool bo1 = false;
			for (int i = 0; i < 4; i++) {
				if (nx + b1[i] < 0 || nx + b1[i] >= 50 || ny + b2[i] < 0 || ny + b2[i] >= 50)continue;
				if (!bo[t[nx + b1[i]][ny + b2[i]]]) {
					bo[t[nx + b1[i]][ny + b2[i]]] = true;
					s.push(make_pair(nx + b1[i], ny + b2[i]));
					bo1 = true;
					break;
				}
			}
			if (!bo1) {
				vec1.emplace_back(make_pair(nx, ny));
				score1 += p[nx][ny];
				while (s.size() > 1) {
					s.pop();
					if (nx == s.top().first + 1) {
						ans1 += 'D';
					}
					if (nx == s.top().first - 1) {
						ans1 += 'U';
					}
					if (ny == s.top().second + 1) {
						ans1 += 'R';
					}
					if (ny == s.top().second - 1) {
						ans1 += 'L';
					}
					nx = s.top().first;
					ny = s.top().second;
					vec1.emplace_back(make_pair(nx, ny));
					score1 += p[nx][ny];
				}
				reverse(ans1.begin(), ans1.end());
				reverse(vec1.begin(), vec1.end());
				if (score < score1) {
					ans = ans1;
					score = score1;
					vec = vec1;
					for (int i = 0; i <= 2500; i++) {
						bo2[i] = bo[i];
					}
				}
				break;
			}
		}
		while (!s.empty()) {
			s.pop();
		}
		s.push(make_pair(x, y));
		for (int i = 0; i <= 2500; i++) {
			bo[i] = false;
		}
		bo[t[x][y]] = true;
	} while (next_permutation(b5, b5 + 4));
	for (int i = 0; i < 10000; i++) {
		int ni = rand() % (vec.size() - 1);
		if (vec[ni].first == vec[ni + 1].first) {
			if (vec[ni].second == vec[ni + 1].second - 1) {
				if (!bo2[t[vec[ni].first][vec[ni].second + 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DRU" + ans.substr(ni, ans.size() - ni);
					}
				}
				if (!bo2[t[vec[ni].first][vec[ni].second - 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second - 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "URD" + ans.substr(ni, ans.size() - ni);
					}
				}
			}
			else {
				if (!bo2[t[vec[ni].first][vec[ni].second + 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DLU" + ans.substr(ni, ans.size() - ni);
					}
				}
				if (!bo2[t[vec[ni].first][vec[ni].second - 1]]) {
					if (!bo2[t[vec[ni + 1].first][vec[ni + 1].second - 1]]) {
						bo2[t[vec[ni].first][vec[ni].second + 1]] = true;
						bo2[t[vec[ni + 1].first][vec[ni + 1].second + 1]] = true;
						ans = ans.substr(0, ni - 1) + "DRU" + ans.substr(ni, ans.size() - ni);
					}
				}
			}
		}
	}
	cout << ans << endl;
}