/*
           _                   _         _       __  __  _____ 
     /\   | |            /\   | |       | |     |  \/  |/ ____|
    /  \  | |__   ___   /  \  | |__   __| | ___ | \  / | |     
   / /\ \ | '_ \ / _ \ / /\ \ | '_ \ / _` |/ _ \| |\/| | |     
  / ____ \| |_) | (_) / ____ \| |_) | (_| | (_) | |  | | |____ 
 /_/    \_\_.__/ \___/_/    \_\_.__/ \__,_|\___/|_|  |_|\_____|

*/

#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld eps = 1e-9;
const int mod = 1e9 + 7;
const int oo = 1e9 + 7;
const ll lloo = 1e18 + 7;
const int N = 1e6 + 7;

void solve();

int main()
{
	// freopen("in","r",stdin);
	// freopen("out","w",stdout);
	int t = 1;
	// scanf("%d",&t);
	while (t--) solve();
	return 0;
}

char buff[N];
int nxt[N],bef[N];
void solve()
{
	scanf("%s",buff);
	string str = buff;
	int n = (int)str.size();
	deque<char> q;
	bool rev = 0;
	for(int i = 0 ; i < n ; i++)
	{
		if (str[i] == 'R') rev = !rev;
		else
		{
			if (rev) q.push_front(str[i]);
			else q.push_back(str[i]);
		}
	}
	
	str = "";
	for(auto x:q) str+=x;
	if (rev) reverse(all(str));
	
	n = (int)str.size();
	for(int i = 0 ; i < n ; i++) {nxt[i] = i+1;bef[i+1] = i;}
	nxt[n+1] = 0;
	bef[0] = n+1;
	//cout << str << endl;
	while(1)
	{
		int tmp = nxt[n+1];
		bool ok = 0;
		while (nxt[tmp] != n)
		{
			if (str[tmp] == str[nxt[tmp]])
			{
				nxt[bef[tmp]] = nxt[nxt[tmp]];
				bef[nxt[nxt[tmp]]] = bef[tmp];
				if (bef[tmp] != n+1) tmp = bef[tmp]; 
				else if (nxt[nxt[tmp]] != n) tmp = nxt[nxt[tmp]];
				else {ok = 0;break;}
				ok = 1;
			}
			else tmp = nxt[tmp];
		}
		if (!ok) break;
	}
	string ans = "";
	int tmp = nxt[n+1];
	while(tmp != n) {ans += str[tmp];tmp = nxt[tmp];}
	printf("%s\n",ans.c_str());
}

#include <bits/stdc++.h>
#include <chrono>
#include <ctime>
using namespace std;
using chrono::steady_clock;
using chrono::milliseconds;

#define sp " "
#define INF 1e18
#define INT_INF 1e9
typedef long long ll;
typedef pair<int,int> P;

chrono::steady_clock::time_point now_t;
chrono::steady_clock::time_point start_t;

random_device x;
mt19937 mt(x());

struct coord { int x; int y; };

const int N = 50;
vector<vector<int>> t(50,vector<int>(50));
vector<vector<int>> p(50,vector<int>(50));
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
char direct[] = {'D','R','U','L'};

struct state {
    //状態を管理
    int l;
    vector<coord> route;
    vector<char> direct;//D,R,U,L 
    vector<int> score;
    vector<int> reach;//0 false 1 true
};


int get_rnd(int mod){
    return mt()%mod;
}

bool TIME_CHECK( int Limit ){
    now_t = steady_clock::now();
    if(chrono::duration_cast<milliseconds>(now_t-start_t) < milliseconds(Limit))return true;
    return false;
}

void enter(state &S){
    //入力
    int sx,sy;
  	cin >> sx >> sy;
  	coord s = {sx,sy};
  	S.route.push_back(s);
    for(int i = 0;i < 2500;i++)S.reach.push_back(0);
  	for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            cin >> t[i][j];
        } 
    }
    for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            cin >> p[i][j];
        }
    }
    S.reach[t[S.route[0].x][S.route[0].y]] = 1;
  	S.score.push_back(p[S.route[0].x][S.route[0].y]);
    S.l = 1;
    return;
}

void output(state S){
    //出力
    int l = S.l;
    for(int i = 0;i < l-1;++i){
        //cout << i << sp << S.route[i+1].x-S.route[0].x << sp << S.route[i+1].y-S.route[0].y << endl; 
        // if(S.route[i+1].x - S.route[i].x == 1)cout << "D";
        // if(S.route[i+1].x - S.route[i].x == -1)cout << "U";
        // if(S.route[i+1].y - S.route[i].y == 1)cout << "R";
        // if(S.route[i+1].y - S.route[i].y == -1)cout << "L";
        // //cout << endl;
        cout << S.direct[i];
    }
}

void dfs(state &S){
    state best_s = S;
    stack<state> st;
    st.push(S);
    while(!st.empty() && st.size() < 1000 && TIME_CHECK(1800)){
      state s = st.top();
      st.pop();
      int cx,cy,l;
      l = s.l;
      cx = s.route[l-1].x;
      cy = s.route[l-1].y;
      for(int i = 0;i < 4;i++){
        state T = s;
        if(cx+dx[i] < 0 || cx+dx[i] >= 50 || cy+dy[i] < 0 || cy+dy[i] >= 50)continue;
        else if(T.reach[t[cx+dx[i]][cy+dy[i]]] == 0){
          coord c = {cx+dx[i],cy+dy[i]};
          T.route.push_back(c);
          T.score.push_back(T.score[l-1] + p[c.x][c.y]);
          if(T.score[l] > best_s.score[best_s.l-1])best_s = T;
          if(st.size() > 50){
            if(T.score[l] < best_s.score[min(l,best_s.l - 1)]*9/10)continue;
          }
          T.reach[t[c.x][c.y]] = 1;
          T.direct.push_back(direct[i]);
          T.l += 1;
          st.push(T);
        }
      }
    }
    S = best_s;
}


//void mountain( state &S){
    //山登り
    // int l = S.l;
    // int n = get_rnd(l);
//}

// void AS ( state &S){
//     //焼きなまし
// }



/*
近傍の取り方でスコア悪化の確立が高すぎるもの、
変化がおおきすぎるものを選ぶとスコア改善しないので、
適切な近傍の取り方を考える
思いつかないなら山登りでよい
極力連続でなだらかな関数にする
近傍の取り方は2種類用意したほうがいい（できれば）
焼きなましの温度は対数的に減らす->確率は線形になる
線形的に減らす->確率は指数的になる

rand()は遅いので使わない
*/
int main(){
    start_t = steady_clock::now();
    state S;
    enter(S);
    // while(true){
    //     int res = greed(S);
    //     if(res == 0)continue;
    //     else break;
    // }
    dfs(S);
    output(S);
}

