#include <bits/stdc++.h>
using namespace std;
int n,m,bl[55][55],val[55][55],di[]={0,0,-1,1},dj[]={1,-1,0,0},nn,mm;
bool vis[2505],p;
int main()
{
    //freopen("in.txt","r",stdin);
    p=true;
    scanf("%d %d",&n,&m);
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<50;j++)
        {
            scanf("%d",&bl[i][j]);
        }
    }
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<50;j++)
        {
            scanf("%d",&val[i][j]);
        }
    }
    while(1)
    {
        vis[bl[n][m]]=true;
        p=false;
        for(int i=0;i<4;i++)
        {
            nn=n+di[i];
            mm=m+dj[i];
            if(nn<0||mm<0||nn>=50||mm>=50)continue;
            if(!vis[bl[nn][mm]])
            {
                if(i==0)printf("R");
                else if(i==1)printf("L");
                else if(i==2)printf("U");
                else printf("D");
                p=true;
                n=nn;
                m=mm;
                //printf(" %d %d\n",n,m);
                break;
            }
        }
        if(!p)break;
    }
}

#include <bits/stdc++.h>

clock_t start;

constexpr int H = 50, W = 50;
int si, sj;
int t[H][W], p[H][W];

struct cand {
    std::string s;
    int score, i, j;
    std::vector<bool> seen;
    bool operator<(const cand& rhs) const { return score < rhs.score; }
    bool valid(const char& c) {
        if (c == 'L') return (0 < j && !seen[t[i][j - 1]]);
        if (c == 'R') return (j < W - 1 && !seen[t[i][j + 1]]);
        if (c == 'U') return (0 < i && !seen[t[i - 1][j]]);
        if (c == 'D') return (i < H - 1 && !seen[t[i + 1][j]]);
    }
    cand move(const char& c) {
        cand ret = *this;
        ret.s.push_back(c);
        if (c == 'L') ret.j--;
        else if (c == 'R') ret.j++;
        else if (c == 'U') ret.i--;
        else ret.i++;
        ret.score += p[ret.i][ret.j];
        ret.seen[t[ret.i][ret.j]] = true;
        return ret;
    }
};

int main() {
    start = clock();

    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin >> si >> sj;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> t[i][j];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> p[i][j];

    constexpr int N = 1000;
    int n = 1;
    std::vector<bool> seen(H * W, false);
    seen[t[si][sj]] = true;
    cand ans = {"", p[si][sj], si, sj, seen};
    std::vector<cand> c(N, ans);
    while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
        std::vector<cand> v;
        for (int i = 0; i < n; i++) {
            ans = std::max(ans, c[i]);
            if (c[i].valid('L')) v.push_back(c[i].move('L'));
            if (c[i].valid('R')) v.push_back(c[i].move('R'));
            if (c[i].valid('U')) v.push_back(c[i].move('U'));
            if (c[i].valid('D')) v.push_back(c[i].move('D'));
        }
        sort(v.begin(), v.end());
        n = std::min(N, (int)v.size());
        int m = n / 2;
        for (int i = 0; i < m; i++) c[i] = v[(int)v.size() - 1 - i];
        if (n == m) continue;
        int skip = ((int)v.size() - m) / (n - m);
        for (int i = 0; i < n - m; i++) c[i + m] = v[i * skip];
    }
    std::cout << std::max(ans, c[0]).s << '\n';
}