#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=int;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
01234でタイルの方向管理？
*/
#define TIMEOVER_M 25000
#define TIMEOVER 1950000

ll T[50][50];
bool B[50][50];
ll P[50][50];
ll D[50][50];
char *ans;
char *W;
ll score=0;
ll high=0;
ll dx[]={0, 1, 0, -1};
ll dy[]={-1, 0, 1, 0};
char dc[]={'U', 'R', 'D', 'L'};
bool all_fin;
bool fin;
clock_t start;
clock_t start_m;
ll loop;

void steped(ll y, ll x, bool b){
  ll d=D[y][x];
  if (d){
    --d;
    ll ny=y+dy[d];
    ll nx=x+dx[d];
    B[ny][nx]=b;
  }
  B[y][x] = b;
}

// 行き止まりになったら、その時点でのstringを出力
void dfs(ll y, ll x, ll c){// {y, x, 歩数}
  bool used[4]={};
  rep(i, 4){
    clock_t now = clock();
    if(now-start_m>TIMEOVER_M) fin=true;
    if(now-start>TIMEOVER) all_fin=true;
    ll r=now%4;
    while(used[r]) (r+=1)%=4;
    used[r]=true;
    ll ny=y+dy[r];
    ll nx=x+dx[r];
//    cout << "time:" << now-start << endl;
    if(ny<0 || nx<0 || ny>49 || nx>49 || B[ny][nx] || fin || all_fin){
      if(chmax(high, score)){
        if(ans) free(ans);
        ans=strdup(W);
      }
    }
    else{
      //反映
      score+=P[ny][nx];
      W[c]=dc[r];
      steped(ny, nx, true);

      dfs(ny, nx, c+1);
      //復元
      score-=P[ny][nx];
      W[c]='\0';
      steped(ny, nx, false);
    }
  }
    
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  W=(char*)calloc(2000, 1);
  start = clock();
  ll si, sj;
  cin >> si >> sj;
  rep(i, 50) rep(j, 50) cin >> T[i][j];
  rep(i, 50) rep(j, 50) cin >> P[i][j];
  // タイルの方向D
  rep(i, 50) rep(j, 50){
    rep(k, 4){
      ll ny=i+dy[k];
      ll nx=j+dx[k];
      if(ny<0 || nx<0 || ny>49 || nx>49) continue;
      if(T[i][j]==T[ny][nx]) D[i][j]=k+1;
    }
  }
  while(!all_fin){
    loop++;
    fin=false;
    start_m = clock();
    score = P[si][sj];
    chmax(high, score);
    rep(y, 50) rep(x, 50) B[y][x]=false;
    rep(i, 2000) W[i]='\0';
    steped(si, sj, true);
    dfs(si, sj, 0);
  }
//  cout << high << " " << loop << endl;
  printf("%s\n", ans);
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define eol endl
// ---------------------------------------------------------------------------

#include<time.h>


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  clock_t start,end;
  start = clock();
  int x = 0;
  int sy,sx;
  cin >> sy >> sx;
  int H = 50;
  int W = 50;
  vector<vector<int>> tile_id(H,vector<int>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> tile_id[i][j];
    }
  }
  vector<vector<int>> score(H,vector<int>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> score[i][j];
    }
  }
  vector<bool> used_id(10000,false);
  string str = "RDLU";
  int sum = 0;
  int ans_sum = 0;
  string ans;
  string now;
  auto solve = [&](){
    bool fin = false; 
    function<void(int,int)> dfs = [&](int y,int x)->void{
      end = clock();
      if((double)(end-start)/CLOCKS_PER_SEC >= 1.95){
        fin = true;
        return;
      } 
      vector<P> can;
      for(int k=0; k<4; k++){
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(ny<0 || ny>=H || nx<0 || nx>=W) continue;
        if(used_id[tile_id[ny][nx]]) continue;
        can.emplace_back(score[ny][nx],k);
      }
      sort(can.rbegin(),can.rend());
      if(can.size() == 0){
        if(chmax(ans_sum,sum)){
          ans = now;
        }
        return;
      }
      for(auto hoge: can){
        int k = hoge.second;
        int ny = y + dy[k];
        int nx = x + dx[k];
        sum += score[ny][nx];
        used_id[tile_id[ny][nx]] = true;
        now += str[k];
        dfs(ny,nx);
        if(fin) return;
        sum -= score[ny][nx];
        used_id[tile_id[ny][nx]] = false;
        now.pop_back();
      }
    };
    sum += score[sy][sx];
    used_id[tile_id[sy][sx]] = true;
    dfs(sy,sx);
    return;
  };
  solve();
  cout << ans << eol;
  return 0;
}