#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

template<class T> bool chmax(T &a, T b) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
}

vector<int> table(2500);
vector<vector<int>> tile(2500);
vector<vector<bool>> seen(50,vector<bool>(50,0));
vector<vector<int>>point(50,vector<int>(50));

int now_x, now_y;
int si, sj;
// ll sum = 0;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<int>ans;

void solve(int now_x, int now_y) {
  while (1) {
    int num = table[now_x+now_y*50];
    for (int j = 0; j < tile[num].size(); j++) {
      int k = tile[num][j];
      seen[k/50][k%50] = 1;
    }


    int nx,ny,index=-1;
    ll ma = -1;
    for (int i = 0; i < 4; i++) {
      nx = now_x + dx[i];
      ny = now_y + dy[i];
      if (nx<0||nx>=50||ny<0||ny>=50) continue;
      if (seen[ny][nx]==1) continue;
      ll score = 0;
      if (i==0) score += 50-now_x;
      else if (i==1) score += 50-now_y;
      else if (i==2) score += now_x;
      else if (i==3) score += now_y;
      score += point[ny][nx] / 10;
      if (chmax(ma, score)) {
        index = i;
      }
    }
    if (index==-1) break;
    now_x = now_x + dx[index];
    now_y = now_y + dy[index];
    ans.push_back(index);
  }
  return;
}

int main()
{
  cin >> sj >> si;
  now_x = si;
  now_y = sj;

  for (int i = 0; i < 2500; i++) {
    int num;
    cin >> num;
    table[i] = num;
    tile[num].push_back(i);
  }
  for (int i = 0; i < 2500; i++) {
    int x = i%50;
    int y = i/50;
    cin >> point[y][x];
  }

  solve(now_x, now_y);
  
  // 出力
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i]==0) cout << 'R';
    else if (ans[i]==1) cout << 'D';
    else if (ans[i]==2) cout << 'L';
    else if (ans[i]==3) cout << 'U';
  }
  cout << endl;
}




#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    char X[H][W];
    string S;
    for (int i = 0; i < H; i++) {
        cin >> S;
        for (int j = 0; j < W; j++) {
            X[i][j] = S.at(j);
        }
    }


    int count = 0;
    for (int i = 0; i < H - 1; i++) {
        for (int j = 0; j < W - 1; j++) {
            if (X[i][j] == '.') {
                if (X[i + 1][j] == '.') {
                    count++;
                }
                if (X[i][j + 1] == '.') {
                    count++;
                }

            }
        }
    }

    for (int i = 0; i < H - 1; i++) {
        if (X[i][W-1] == '.' && X[i+1][W-1] == '.') {
            count++;
        }
    }
    for (int i = 0; i < W - 1; i++) {
        if (X[H-1][i] == '.' && X[H-1][i+1] == '.') {
            count++;
        }
    }

    cout << count << endl;

}
