/** author: samari06,  created: 09.03.2021 21:49:15 **/
#include <bits/stdc++.h>
#define REP(i, N) for(int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> Vll;


int t[55][55], p[55][55], sx, sy;
int cscr = 0, bstscr = 0;
string dist = "RLDU";

class Timer {
    private:
        clock_t time_start;    // 計測開始時間

    public:
        Timer() { restart(); }

        void restart() {
            time_start = clock();
        }

        clock_t elaps() {             // 計測開始時間からの秒数を返す
            clock_t time_end = clock();
            return (time_end - time_start);
        }
};

// 疑似乱数列生成 (https://ja.wikipedia.org/wiki/Xorshift)
uint32_t xor32(void) {
  static uint32_t y = 2463534242;
  y ^= (y << 13); y ^= (y >> 17);  y ^= (y << 5);
  return y;
}

// 0以上1未満の小数をとる乱数
double rand01() {
    return (xor32()+0.5)*(1.0/UINT_MAX);
}

int score(string &s){
    int ch[2500] = {0};
    int scr = p[sx][sy];
    int px = sx, py = sy;
    ch[t[sx][sy]] = 1;
    REP(i,s.size()){
        if(s[i] == 'R'){
            py++;
            if(py >= 50) return 0;
            if(ch[t[px][py]]) return 0;
        }else if(s[i] == 'L'){
            py--;
            if(py < 0) return 0;
            if(ch[t[px][py]]) return 0;
        }else if(s[i] == 'D'){
            px++;
            if(px >= 50) return 0;
            if(ch[t[px][py]]) return 0;
        }else if(s[i] == 'U'){
            px--;
            if(px < 0) return 0;
            if(ch[t[px][py]]) return 0;
        }

        ch[t[px][py]] = 1;
        scr += p[px][py];
    }

    return scr;
}

string solve(){
    string ans;
    Timer tmr;
    const double TL = 1.9;
    double time = 0.0;

    // 初期解の生成
    while(time < TL){
        time = (double)tmr.elaps() / CLOCKS_PER_SEC;

        string tans;
        tans += dist[xor32()%4];
        if(score(tans) != 0){
            ans = tans;
            break;
        }
    }

    
    while(time < TL){
        time = (double)tmr.elaps() / CLOCKS_PER_SEC;
        int id = xor32()%ans.size();
        string tans = ans;
        int tscr = bstscr;

        id = (int)tans.size()-1;

        if(id+1 == tans.size()){
            tans += dist[xor32()%4];
            if(score(tans) == 0) continue;
        }else{

        }

        ans = tans;
    }



    return ans;
}


int main(){
    // 入力
    scanf("%d%d", &sx, &sy);
    REP(j,50) REP(i,50) scanf("%d", &t[j][i]);
    REP(j,50) REP(i,50) scanf("%d", &p[j][i]);
    
    // 求解
    string sol = solve();

    // 出力
    cout << sol << "\n";

    // score
    //printf("score: %d\n",score(sol));

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