#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

template<class T> bool chmax(T &a, T b) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
}

vector<int> table(2500);
vector<vector<int>> tile(2500);
vector<vector<bool>> seen(50,vector<bool>(50,0));
vector<vector<int>>point(50,vector<int>(50));

int now_x, now_y;
// ll sum = 0;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<int>ans;

void solve(int now_x, int now_y) {
  while (1) {
    int num = table[now_x+now_y*50];
    for (int j = 0; j < tile[num].size(); j++) {
      int k = tile[num][j];
      seen[k/50][k%50] = 1;
    }


    int nx,ny,ma=0,index=-1;
    for (int i = 0; i < 4; i++) {
      nx = now_x + dx[i];
      ny = now_y + dy[i];
      if (nx<0||nx>=50||ny<0||ny>=50) continue;
      if (seen[ny][nx]==1) continue;
      if (chmax(ma, point[ny][nx])) {
        index = i;
      }
    }
    if (index==-1) break;
    now_x = now_x + dx[index];
    now_y = now_y + dy[index];
    ans.push_back(index);
  }
  return;
}

int main()
{
  int si, sj;
  cin >> sj >> si;
  now_x = si;
  now_y = sj;

  for (int i = 0; i < 2500; i++) {
    int num;
    cin >> num;
    table[i] = num;
    tile[num].push_back(i);
  }
  for (int i = 0; i < 2500; i++) {
    int x = i%50;
    int y = i/50;
    cin >> point[y][x];
  }

  solve(now_x, now_y);
  
  // 出力
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i]==0) cout << 'R';
    else if (ans[i]==1) cout << 'D';
    else if (ans[i]==2) cout << 'L';
    else if (ans[i]==3) cout << 'U';
  }
  cout << endl;
}




#include <iostream>
#include <queue>

using namespace std;

int R, C;
int A[501][501], B[501][501];

int dijkstra() {
    bool used[501][501] = {};
    int minScore[501][501] = {};
    for(int i = 0;i < 501;i++) {
        for(int j = 0;j < 501;j++) {
            minScore[j][i] = 1000000000;
        }
    }

    priority_queue<pair<int, pair<int, int>>> que;
    que.push(make_pair(0, make_pair(0, 0)));

    while(que.size()) {
        pair<int, pair<int, int>> now = que.top();
        que.pop();

        int score = -now.first;
        int x = now.second.first;
        int y = now.second.second;

        if (x == C-1 && y == R-1) {
            return score;
        }

        if (used[x][y]) continue;
        // cout << y + 1 << ", " << x + 1 << " = " << score << endl;
        used[x][y] = true;

        // 1
        int nextScore, toX, toY;
        if (x < C-1) {
            nextScore = score + A[x][y];
            toX = x + 1;
            toY = y;
            if(!used[toX][toY] && minScore[toX][toY] > nextScore) {
                minScore[toX][toY] = nextScore;
                que.push(make_pair(-nextScore, make_pair(toX, toY)));
            }
        }

        // 2
        if (x > 0) {
            nextScore = score + A[x-1][y];
            toX = x - 1;
            toY = y;

            if(!used[toX][toY] && minScore[toX][toY] > nextScore) {
                minScore[toX][toY] = nextScore;
                que.push(make_pair(-nextScore, make_pair(toX, toY)));
            }
        }

        // 3
        if (y < R-1) {
            nextScore = score + B[x][y];
            toX = x;
            toY = y + 1;

            if(!used[toX][toY] && minScore[toX][toY] > nextScore) {
                minScore[toX][toY] = nextScore;
                que.push(make_pair(-nextScore, make_pair(toX, toY)));
            }
        }

        // 4
        for (int i = 1;i <= y;i++) {
            nextScore = score + 1 + i;
            toX = x;
            toY = y - i;

            if(!used[toX][toY] && minScore[toX][toY] > nextScore) {
                minScore[toX][toY] = nextScore;
                que.push(make_pair(-nextScore, make_pair(toX, toY)));
            }
        }
    }

    return 0;
}

int main() {
    cin >> R >> C;
    for(int i = 0;i < R;i++){
        for(int j = 0;j < C-1;j++) {
            cin >> A[j][i];
        }
    }

    for(int i = 0;i < R-1;i++){
        for(int j = 0;j < C;j++) {
            cin >> B[j][i];
        }
    }

    int ans = dijkstra();

    cout << ans << endl;

    return 0;
}