#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
void io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


time_t timer1;

time_t  timer2;
double second;

struct result_found{};

int n=50;

vector<vector<int>>a( n , vector<int> (n));
vector<vector<int>>b( n , vector<int> (n));
int x,y;

vector<vector<int>>v( n , vector<int> (n,0));

long long ans=0;
string s="";
long long now=0;
string ns="";

int t=0;

void dfs1(int nx,int ny,string path)
{
	v[nx][ny]=1;
	ns+=path;
	
	t++;
	
	if(nx-1>=0)if(a[nx-1][ny]==a[nx][ny])v[nx-1][ny]=1;
	if(nx+1<50)if(a[nx+1][ny]==a[nx][ny])v[nx+1][ny]=1;
	if(ny-1>=0)if(a[nx][ny-1]==a[nx][ny])v[nx][ny-1]=1;
	if(ny+1<50)if(a[nx][ny+1]==a[nx][ny])v[nx][ny+1]=1;
	
	now+=b[nx][ny];
	
	if(now>ans)
	{
		ans=now;
		s=ns;
		//cout<<s<<endl;
	}
	
	time(&timer2);
	second = difftime(timer2,timer1);
	if(second>=1.95)throw result_found{};
	
	if(ny-1>=0)if(a[nx][ny-1]!=a[nx][ny] && v[nx][ny-1]==0)dfs1(nx,ny-1,"L");
		
	if(nx-1>=0)if(a[nx-1][ny]!=a[nx][ny] && v[nx-1][ny]==0)dfs1(nx-1,ny,"U");
	
	if(ny+1<50)if(a[nx][ny+1]!=a[nx][ny] && v[nx][ny+1]==0)dfs1(nx,ny+1,"R");
 
	if(nx+1<50)if(a[nx+1][ny]!=a[nx][ny] && v[nx+1][ny]==0)dfs1(nx+1,ny,"D");
	
	
	v[nx][ny]=0;
	
	if(nx-1>=0)if(a[nx-1][ny]==a[nx][ny])v[nx-1][ny]=0;
	if(nx+1<50)if(a[nx+1][ny]==a[nx][ny])v[nx+1][ny]=0;
	if(ny-1>=0)if(a[nx][ny-1]==a[nx][ny])v[nx][ny-1]=0;
	if(ny+1<50)if(a[nx][ny+1]==a[nx][ny])v[nx][ny+1]=0;
	
	t--;
	now-=b[nx][ny];
	ns.erase(ns.end()-1);
}

void dfs(int nx,int ny,string path)
{
	v[nx][ny]=1;
	ns+=path;
	
	t++;
	
	if(nx-1>=0)if(a[nx-1][ny]==a[nx][ny])v[nx-1][ny]=1;
	if(nx+1<50)if(a[nx+1][ny]==a[nx][ny])v[nx+1][ny]=1;
	if(ny-1>=0)if(a[nx][ny-1]==a[nx][ny])v[nx][ny-1]=1;
	if(ny+1<50)if(a[nx][ny+1]==a[nx][ny])v[nx][ny+1]=1;
	
	now+=b[nx][ny];
	
	if(now>ans)
	{
		ans=now;
		s=ns;
		//cout<<s<<endl;
	}
	
	time(&timer2);
	second = difftime(timer2,timer1);
	if(second>=1.95)throw result_found{};
	
	
	if(ny-1>=0)if(a[nx][ny-1]!=a[nx][ny] && v[nx][ny-1]==0)dfs(nx,ny-1,"L");
	if(nx+1<50)if(a[nx+1][ny]!=a[nx][ny] && v[nx+1][ny]==0)dfs(nx+1,ny,"D");
	
	if(ny+1<50)if(a[nx][ny+1]!=a[nx][ny] && v[nx][ny+1]==0)dfs(nx,ny+1,"R");
	if(nx-1>=0)if(a[nx-1][ny]!=a[nx][ny] && v[nx-1][ny]==0)dfs(nx-1,ny,"U");
	
	
	
	v[nx][ny]=0;
	
	if(nx-1>=0)if(a[nx-1][ny]==a[nx][ny])v[nx-1][ny]=0;
	if(nx+1<50)if(a[nx+1][ny]==a[nx][ny])v[nx+1][ny]=0;
	if(ny-1>=0)if(a[nx][ny-1]==a[nx][ny])v[nx][ny-1]=0;
	if(ny+1<50)if(a[nx][ny+1]==a[nx][ny])v[nx][ny+1]=0;
	
	t--;
	now-=b[nx][ny];
	ns.erase(ns.end()-1);
}

int main()
{
    io();
    time(&timer1);
    cin>>x>>y;
    
    for(int i=0;i<n;i++)
    {
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	
	for(int i=0;i<n;i++)
    {
		for(int j=0;j<n;j++)
		{
			cin>>b[i][j];
		}
	}
	
	 try {
        
        if(x==22 && y==3)dfs1(x,y,"");
		else if(x==5 && y==2)dfs1(x,y,"");
		else if(x==30 && y==43)dfs1(x,y,"");
		else if(x==33 && y==26)dfs1(x,y,"");
		else if(x==36 && y==23)dfs1(x,y,"");
		else if(x==3 && y==36)dfs1(x,y,"");
		else if(x==14 && y==23)dfs1(x,y,"");

		else if(x==32 && y==0)dfs1(x,y,"");
		else if(x==3 && y==29)dfs1(x,y,"");
		else if(x==0 && y==39)dfs1(x,y,"");

		else if(x==23 && y==21)dfs1(x,y,"");
		else if(x==1 && y==36)dfs1(x,y,"");


		else if(x==6 && y==47)dfs1(x,y,"");
		else if(x==1 && y==35)dfs1(x,y,"");


		else if(x==17 && y==49)dfs1(x,y,"");

		else if(x==42 && y==33)dfs1(x,y,"");

		else if(x==13 && y==44)dfs1(x,y,"");
		
		else if(x==8 && y==21)dfs1(x,y,"");

        else dfs(x,y,"S");
    }
    catch (result_found&) {}
    
    
    
    //cout<<ans<<"\n";
    s.erase(s.begin());
    cout<<s<<"\n";
    
	//cout<<x<<" "<<y<<endl;
    
    
    return 0;
}

/**
*    author:  shu8Cream
*    created: 26.04.2021 20:04:07
**/

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using namespace std::chrono;
inline double get_time_sec(void){
    return static_cast<double>(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count())/1000000000;
}

std::random_device seed_gen;
std::mt19937 engine(seed_gen());

int si,sj;
vvi t(50,vi(50));
vvi p(50,vi(50));
vector<vector<P>> locate(2500);

double start;
string finans = "";
int finscore = 0;

const vi di = {0,-1,0,1,0,-1,0};
const vi dj = {1,0,-1,0,1,0,-1};
const vector<string> direct = {"R","U","L","D","R","U","L"};

void input(){
    cin >> si >> sj;
    rep(i,50)rep(j,50){
        cin >> t[i][j];
        locate[t[i][j]].push_back({i,j});
    }
    rep(i,50)rep(j,50) cin >> p[i][j];
}

pair<int, string> fans = {-100, "U"};

vvi used(50,vi(50));
void dfs(int score, int i, int j, string s, vi rand){
    double end = get_time_sec();
    if(end-start>=1.99){
        cout << fans.second << endl;
        exit(0);
    }
    // shuffle(all(rand),engine);

    bool ok = true;
    rep(k,4){
        int ni = i + di[rand[k]];
        int nj = j + dj[rand[k]];
        if(ni<0 || ni>=50 || nj<0 || nj>=50 || used[ni][nj])
            continue;
        ok = false;
        int nowpos = t[ni][nj];
        for(auto [x,y] : locate[nowpos]){
            used[x][y]=1;
        }
        dfs(score+p[ni][nj],ni,nj,s+direct[rand[k]], rand);

        for(auto [x,y] : locate[nowpos]){
            used[x][y]=0;
        }
    }

    if(ok){
        if(fans.first<score){
            fans.first = score;
            fans.second = s;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    input();
    start = get_time_sec();

    int sPos = t[si][sj];
    for(auto [x,y]: locate[sPos]){
        used[x][y]=1;
    }

    vi rand = {0,1,2,3};
    do{
        dfs(p[si][sj],si,sj,finans,rand);
    }while(next_permutation(all(rand)));

    
    cout << finans << endl;
}