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


using ll = long long;
using que_type = tuple<int, pair<int, int>, vector<int>>;

void solve(long long si, long long sj, std::vector<std::vector<long long>> t, std::vector<std::vector<long long>> p){
    priority_queue<que_type, vector<que_type>, greater<que_type>> que;
    que.push(make_tuple(p[si][sj], make_pair(si, sj), vector<int>{(int)t[si][sj]}));

    int times = 1000;
    int beam = 10;

    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int ans = 0;
    vector<int> ansv;

    while(times--){
        priority_queue<que_type, vector<que_type>, greater<que_type>> next_que;

        while(!que.empty()){
            que_type q = que.top();
            int score;
            pair<int, int> pos;
            vector<int> tiles;
            tie(score, pos, tiles) = q;

            que.pop();


            for(int i = 0;i < 4;i++){
                int nx = dx[i] + pos.first;
                int ny = dy[i] + pos.second;
                if(0 <= dx[i] + pos.first && dx[i] + pos.first < 50 && 0 <= dy[i] + pos.second && dy[i] + pos.second < 50){
                    bool f = false;
                    for(int x : tiles){
                        if(x == t[nx][ny]){
                            f = true;
                            break;
                        }
                    }
                    if(f == false){
                        tiles.push_back(t[nx][ny]);
                        next_que.push(make_tuple(score + p[nx][ny], make_pair(nx, ny), tiles));
                        tiles.pop_back();
                        if(score + p[nx][ny] > ans){
                            ans = score + p[nx][ny];
                            ansv = tiles;
                        }
                    }
                }
            }
        }
        while(next_que.size() > beam)
            next_que.pop();
        que = next_que;
        //cout<<que.size()<<endl;
        //cout<<ans<<endl;
    }

    int pi = si;
    int pj = sj;
    string ans_str;
    for(int i = 1;i < ansv.size();i++){
        bool f = false;
        //cout<<ansv[i]<<" ";
        for(int idx = 0;idx < 4;idx++){
            int nx = pi + dx[idx];
            int ny = pj + dy[idx];

            if(0 <= nx && nx < 50 && 0 <= ny && ny < 50){
                if(t[nx][ny] == ansv[i]){
                    //cout<<idx<<" ";
                    if(idx == 0){
                        ans_str.push_back('D');
                    }else
                    if(idx == 1){
                        ans_str.push_back('R');
                    }else
                    if(idx == 2){
                        ans_str.push_back('U');
                    }else
                    if(idx == 3){
                        ans_str.push_back('L');
                    }
                    f = true;
                }
            }
            if(f){
                pi = nx;
                pj = ny;
                break;
            }
        }
    }
    cout<<ans_str<<endl;
}

int main(){
    long long si;
    scanf("%lld",&si);
    long long sj;
    scanf("%lld",&sj);
    std::vector<std::vector<long long>> t(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&t[i][j]);
        }
    }
    std::vector<std::vector<long long>> p(49+1, std::vector<long long>(49+1));
    for(int i = 0 ; i < 49+1 ; i++){
        for(int j = 0 ; j < 49+1 ; j++){
            scanf("%lld",&p[i][j]);
        }
    }
    solve(si, sj, std::move(t), std::move(p));
    return 0;
}

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

#define hi {ios_base::sync_with_stdio(false);}
#define mani_jo {cin.tie(NULL);}

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
#define pp pair<ll,ll>
#define MAX 10000000
#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define sp " "
#define line "\n"
const int MOD = 1e9+7;

/*
ll power(ll a, ll b) 
{
    ll res = 1;
    while (b > 0) 
    {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
} 
*/


void solve(ll tc = 0)
{
    ll n,q;
    cin>>n>>q;
    ll a[n];
    vi ans(n);
    for(ll i=0;i<n;i++) cin>>a[i];

    for(ll i=0;i<n;i++)
    {
       ans[i] = a[i] - (i+1);
    }
    while(q--)
    {
        ll k;
        cin>>k;

        const int idx = lower_bound(all(ans),k) - ans.begin();

        if(idx == n) cout<<a[n-1] +( k - ans[n-1])<<line;
        else cout<<a[idx] - (ans[idx] - k +1)<<line;
    }
}

int main()
{
    hi mani_jo
  
    ll T{1};
   // cin>>T;
    for(ll t=0;t<T;t++) solve(t);
    
    return 0;
}