#include <bits/stdc++.h>
#include <time.h>
#define rep(i, n)	for(int i=0;i<(int)(n);i++)
#define ALL(a)	(a).begin(),(a).end()
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define TIME_LIMIT  1.5

int sy,sx;
int t[50][50],p[50][50];
int dx[4]={0, 0, -1, 1}, dy[4]={-1, 1, 0, 0};
map<char,int> mp;

inline void InitRand()
{
    srand((unsigned int)time(NULL));
}

struct STATE{
    bool visited[50][50];
    vector<char> route;
    int y,x;
};

void check_sametile(STATE& state){
    rep(i,4){
        int ny=state.y+dy[i], nx=state.x+dx[i];
        if(0<=ny&&ny<50&&0<=nx&&nx<50&&t[ny][nx]==t[state.y][state.x]){
            state.visited[ny][nx]=true;
            break;
        }
    }
}

void init(STATE& state){
    state.y=sy; state.x=sx;
    rep(i,50) fill(state.visited[i],state.visited[i]+50,false);
    state.visited[sy][sx]=true;
    check_sametile(state);
}

void modify(STATE& state){
    int R=rand()%4;
    if(R==0 && state.y-1>=0 && !state.visited[state.y-1][state.x]){
        state.y--;
        state.route.push_back('U');
    }
    else if(R==1 && state.y+1<=49 && !state.visited[state.y+1][state.x]){
        state.y++;
        state.route.push_back('D');
    }
    else if(R==2 && state.x-1>=0 && !state.visited[state.y][state.x-1]){
        state.x--;
        state.route.push_back('L');
    }
    else if(R==3 && state.x+1<=49 && !state.visited[state.y][state.x+1]){
        state.x++;
        state.route.push_back('R');
    }
    if(!state.visited[state.y][state.x]){
        state.visited[state.y][state.x]=true;
        check_sametile(state);
    }
}

int calc_score(STATE& state){
    int res=p[sy][sx];
    int y=sy, x=sx;
    for(auto c:state.route){
        y+=dy[mp[c]]; x+=dx[mp[c]];
        res+=p[y][x];
    }
    return res;
}

STATE pre_state[5];
STATE reset_state;

pair<int,vector<char>> mountain(){
    STATE state;
    init(state);
    //double start_time = clock();
    int cnt=0,re=0,mov=0;
    while(cnt<=2500){
        // double now_time = clock();
        // if(now_time - start_time > TIME_LIMIT) break;

        STATE new_state = state;
        modify(new_state);
        if(state.x==new_state.x&&state.y==new_state.y) re++;
        else{
            for(int i=min(mov,5)-1;i>0;i--){
                pre_state[i]=pre_state[i-1];
            }
            pre_state[0]=state;
            re=0;
            state=new_state;
            mov++;
        }
        if(re>=20||reset_state.x==state.x&&reset_state.y==state.y){
            reset_state=state;
            if(mov<=5) break;
            else{
                state=pre_state[4];
            }
            re=0;
        }
        cnt++;
    }
    return {calc_score(state),state.route};
}

int main(){
    cin>>sy>>sx;
    rep(i,50) rep(j,50) cin>>t[i][j];
    rep(i,50) rep(j,50) cin>>p[i][j];
    mp['U']=0;
    mp['D']=1;
    mp['L']=2;
    mp['R']=3;
    vector<pair<int,vector<char>>> res;
    InitRand();
    rep(i,250){
        reset_state.y=-1; reset_state.x=-1;
        res.push_back(mountain());
    }
    sort(ALL(res),greater<pair<int,vector<char>>>());
    for(auto x:res[0].second) cout<<x;
    cout<<endl;
    //rep(i,10) cout<<res[i].first<<endl;
}
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define p(x,y) pair<x,y>
#define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define scan(a) for(auto &it:a)cin>>it;
#define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;}
#define out(x) cout<<((x)?"Yes":"No")<<endl;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define int ll

void solve()
{
    int n,q;
    cin>>n>>q;
    vector<int> a(n);
    scan(a);
    sort(all(a));
    n=unique(all(a))-a.begin();
    a.resize(n);
    int b[n],c[n];
    // print(a);
    rep(i,0,n)
    b[i]=a[i]-(i>0)*(a[i-1])-1;
    partial_sum(b,b+n,c);
    // print(c);
    while(q--)
    {
        int x;
        cin>>x;
        int in=lower_bound(c,c+n,x)-c;
        if(in==n||a[in]!=x)
            in--;
        if(in>=0LL)
            x-=c[in];
        int no=0LL;
        if(in>=0LL)
            no=a[in];
        no+=x;
        cout<<no<<endl;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t=1;
    //init();
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
