#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;

int main() {
  
  ll si,sj;cin>>si>>sj;
  vector<vector<ll>> t(50, vector<ll>(50));
  vector<vector<ll>> p(50, vector<ll>(50));
  for(ll i=0;i<50;i++){
   for(ll j=0;j<50;j++){
    cin>>t[i][j]; 
   }
  }
  for(ll i=0;i<50;i++){
   for(ll j=0;j<50;j++){
    cin>>p[i][j]; 
   }
  }
  if(si>24&&sj>24){
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
     ll SI=si,SJ=sj;
    bitset<24> BIT(tmp);
     string s="";
     ll sum=0;
//0は上、1は左
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='L';
         }
       }else{
         SI--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='U';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else if(si>24&&sj<=24){
      string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     string s="";
     ll sum=0;
//0は上、1は右
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='R';
         }
       }else{
         SI--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='U';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else if(si<=24&&sj>24){
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
     string s="";
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     ll sum=0;
//0は下、1は左
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ--;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='L';
         }
       }else{
         SI++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='D';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }else{
    string S="";
    ll maxsum=-1;
   for (int tmp = 0; tmp < (1 << 24); tmp++) {
    bitset<24> BIT(tmp);
     ll SI=si,SJ=sj;
     string s="";
     ll sum=0;
//0は下、1は右
     bool a=true;
     ll b=t[SI][SJ];
     for(int i=0;i<24;i++){
       if(BIT.test(i)){
         SJ++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='R';
         }
       }else{
         SI++;
         if(b==t[SI][SJ]){
           sum=-1;
           a=false;
          break; 
         }else{
          sum+=p[SI][SJ];
           b=t[SI][SJ];
           s+='D';
         }
       }
       if(maxsum<sum){
         maxsum=sum;
         S=s;
       }
     }
  }
    cout<<S;
    return 0;
  }
  
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

//data
const int h = 50;
int tile[50][50];
int point[50][50];
int use[3000]; // not used 0,used 1

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
char direction[] = {'D','U','R','L'};

vector<char> ans;

//function
bool onboad(int i,int j) {return 0<=i && i<h && 0<=j && j<h;}

bool can_reach(int i,int j,int c){
    if(c==0) return true;
    bool ok = false;
    use[ tile[i][j] ] = 1;
    rep(k,4){
        int new_i = i + dx[k];
        int new_j = j + dy[k];
        if(!onboad(new_i,new_j)) continue;
        if(use[ tile[new_i][new_j] ] == 1) continue;
        ok = ok || can_reach(new_i,new_j,c-1);
        if(ok) break;
    }
    use[ tile[i][j] ] = 0;
    return ok;
}

void dfs(int i,int j){
    int res = -1;
    char c;
    int next_i,next_j;
    use[ tile[i][j] ] = 1;
    rep(k,4){
        int new_i = i + dx[k];
        int new_j = j + dy[k];
        if(!onboad(new_i,new_j)) continue;
        if(use[ tile[new_i][new_j] ] == 1) continue;
        if(res == -1 || can_reach(new_i,new_j,30) ){
            res = point[new_i][new_j];
            c = direction[k];
            next_i = new_i;
            next_j = new_j;
        }
    }
    if(res == -1) return;
    ans.push_back(c);
    dfs(next_i,next_j);
    return;
}

//score
int score(int si,int sj){
    int tmpi = si,tmpj = sj;
    int res = point[si][sj];
    for(auto c:ans){
        if(c=='D') tmpi += dx[0],tmpj += dy[0]; 
        if(c=='U') tmpi += dx[1],tmpj += dy[1]; 
        if(c=='R') tmpi += dx[2],tmpj += dy[2]; 
        if(c=='L') tmpi += dx[3],tmpj += dy[3]; 
        res += point[tmpi][tmpj];
    }
    return res;
}

FILE *fp;


int main(){
    int si,sj;
    cin >> si >> sj;
    rep(i,h)rep(j,h) cin >> tile[i][j];
    rep(i,h)rep(j,h) cin >> point[i][j];
    dfs(si,sj);

    for(auto c:ans) cout << c;
    cout << endl;

    #ifdef LOCAL_
    fp = fopen("score.txt","w");
    fprintf(fp,"%d\n",score(si,sj));
    fclose(fp);
    #endif

    return 0;
}