#include<bits/stdc++.h> 
using namespace std;
int Nx,Ny;
const bool debug=false;
struct tile_map{
  private:

  int m[50][50];
  int c[50][50];
  bool visited[50][50];
  public:
  int64_t score=0;
  string ans="";
  int get(int x,int y){
    if(x>=0&&x<50&&y>=0&&y<50){
      return m[x][y];
    }else{
      if(debug)puts("Mindex errer");
      return -1;
    }
  }
  void init(){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cin>>m[i][j];
    }
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cin>>c[i][j];
    }
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)visited[i][j]=false;
    }
    visited[Nx][Ny]=true;
    int t=get(Nx,Ny);
    if(get(Nx+1,Ny)==t)visited[Nx+1][Ny]=true;
    if(get(Nx-1,Ny)==t)visited[Nx-1][Ny]=true;
    if(get(Nx,Ny+1)==t)visited[Nx][Ny+1]=true;
    if(get(Nx,Ny-1)==t)visited[Nx][Ny-1]=true;
  }
  int cost(int x,int y){
    if(x>=0&&x<50&&y>=0&&y<50){
      if(visited[x][y])return -1;
      else return c[x][y];
    }else{
      if(debug)puts("Cindex errer");
      return -1;
    }
  }
  map<char,array<int,3>> next(){
    map<char,array<int,3>>mv;
    if(Nx+1<50&&!visited[Nx+1][Ny]){
      mv['D']={Nx+1,Ny,cost(Nx+1,Ny)};
    }
    if(Nx-1>=0&&!visited[Nx-1][Ny]){
      mv['U']={Nx-1,Ny,cost(Nx-1,Ny)};
    }
    if(Ny+1<50&&!visited[Nx][Ny+1]){
      mv['R']={Nx,Ny+1,cost(Nx,Ny+1)};
    }
    if(Ny-1>=0&&!visited[Nx][Ny-1]){
      mv['L']={Nx,Ny-1,cost(Nx,Ny-1)};
    }
    return mv;
  }
  bool go(int x,int y){
    if(abs(x-Nx)+abs(y-Ny)!=1){
      if(debug)puts("can not go");
      return false;
    }
    if(visited[x][y]){
      return false;
    }else{
      if(x==Nx+1)ans+='D';
      if(x==Nx-1)ans+='U';
      if(y==Ny+1)ans+='R';
      if(y==Ny-1)ans+='L';
      score+=cost(x,y);
      visited[x][y]=true;
      int t=get(x,y);
      if(get(x+1,y)==t)visited[x+1][y]=true;
      if(get(x-1,y)==t)visited[x-1][y]=true;
      if(get(x,y+1)==t)visited[x][y+1]=true;
      if(get(x,y-1)==t)visited[x][y-1]=true;
      Nx=x,Ny=y;
      return true;
    }
  }
  void print(){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++)cout<<(visited[i][j]?'x':'o');puts("");
    }
  }
};
int main(){
  cin>>Nx>>Ny;
  tile_map M;
  M.init();
  if(debug)M.print();
  auto t=M.next();
  while(!t.empty()){
    if(Nx<25&&Ny<25){
      if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }
    }else if(Nx<25){
      if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }
    }else if(Ny<25){
      if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }else if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }
    }else{
      if(t.count('U')){
        M.go(t['U'][0],t['U'][1]);
      }else if(t.count('R')){
        M.go(t['R'][0],t['R'][1]);
      }else if(t.count('L')){
        M.go(t['L'][0],t['L'][1]);
      }else if(t.count('D')){
        M.go(t['D'][0],t['D'][1]);
      }
    }
    t=M.next();
  }
  cout<<M.ans<<'\n';
  if(debug)cout<<M.score<<'\n';
  if(debug){
    M.print();
    cout<<Nx<<' '<<Ny<<'\n';
    for(auto [x,y]:M.next()){
      cout<<y[0]<<' '<<y[1]<<'\n';
    }
  }
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(x)  cerr << #x << " = " << (x) << endl;

constexpr int mod = (1<<30)-1;
inline int xor128() {
    static int x = 123456789;
    static int y = 362436069;
    static int z = 521288629;
    static int w = 88675123;
    int t;
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
 

inline int randInt(int l,int r){
    return l+xor128()%(r-l);
}

inline double getprob(){
    return (xor128()%mod)/(double) mod;
}
 
class TimeCheck {
private:
    chrono::system_clock::time_point start, end;
 
public:
    TimeCheck(){start = chrono::system_clock::now();}
 
    double nowTime() {
        end = chrono::system_clock::now();
        double ti = static_cast<double>(
            chrono::duration_cast<chrono::microseconds>(end-start).count()/1000.0);
        return ti;
    }
};

constexpr int N = 50;
vec<int> dx = {-1,0,1,0},dy = {0,-1,0,1};
string D = "ULDR";
vvec<int> T(N,vec<int>(N)),P = T;

bool in(int x,int y){
    return 0<=x && x<N && 0<=y && y<N;
}

struct state{
    int px,py;
    int score;
    string S;
    unordered_set<int> vis;
    state(){}
    state(int sx,int sy):px(sx),py(sy){
        score = P[sx][sy];
        vis.insert(T[sx][sy]);
        S = "";
    }
    bool is_valid_move(int nx,int ny){
        return in(nx,ny) && !vis.count(T[nx][ny]);
    }
    void move(int id){
        S += D[id];
        px += dx[id];
        py += dy[id];
        vis.insert(T[px][py]);
        score += P[px][py];
    }
    bool operator<(const state& r) const{
        return score>r.score;
    }
};

vec<state> generate_move(state& s,int len){
    vec<state> res;
    auto dfs = [&](auto&& self,int x,int y,int t)->void{
        if(t==len){
            res.push_back(s);
            return ;
        }
        rep(i,4){
            int nx = x+dx[i],ny = y+dy[i];
            if(!s.is_valid_move(nx,ny)) continue;
            s.move(i);
            self(self,nx,ny,t+1);
            s.S.pop_back();
            s.score -= P[nx][ny];
            s.vis.erase(T[nx][ny]);
            s.px = x,s.py = y;
        }
    };
    dfs(dfs,s.px,s.py,0);
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy;
    cin >> sx >> sy;
    rep(i,N) rep(j,N){
        cin >> T[i][j];
    }
    rep(i,N) rep(j,N) cin >> P[i][j];
    state init(sx,sy);
    const int width = 50;
    vec<state> que;
    que.push_back(init);
    state ans = init;
    rep(t,2500) if(!que.empty()){
        vec<state> nq;
        for(auto& s:que){
            auto res = generate_move(s,4);
            sort(all(res));
//            if(res.size()>5) res.resize(5);
            for(auto& ns:res) nq.push_back(ns);
        }
        sort(all(nq));
        if(nq.size()>width) nq.resize(width);
        if(nq.empty()) break;
        que.swap(nq);
        
    }
    sort(all(que));
    ans = que[0];
    cerr << "ok\n";
    cout << ans.S << "\n";
}