#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
random_device rd;
mt19937 mt(rd());
int main(){
    ll N,M;
    cin >> N >> M;
    vector<string> S(M),ans(N),T;
    map<string,ll> ss;
    ll m = MAX;
    for(ll i = 0;i < M;i++) cin >> S[i];
    for(ll i = 0;i < M;i++) ss[S[i]] = i + 1;
    for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size());
    for(ll t = 0;t < 4000;t++){
        string a = S[mt() % M];
        for(ll i = 0;i < 10;i++){
            string b = S[mt() % M];
            for(ll j = min(a.size(),b.size());j >= 0;j--){
                ll ok = 1;
                for(ll k = 0;k < j;k++){
                    if(a[a.size() - j + k] != b[j]) ok = 0;
                }
                if(ok){
                    ll k = j;
                    while(a.size() < N && k < b.size()){
                        a += b[k];
                        k++;
                    }
                    break;
                }
            }
            if(a.size() + b.size() <= N){
                a += b;
            }
        }
        while(a.size() < N) a += (char)('A' + (mt() % 8));
        T.emplace_back(a);
    }
    for(ll i = 0;i < N;i++){
        ll C = 0;
        string A = "____________________";
        for(ll j = 0;j < T.size();j++){
            ll c = 0;
            string a = T[j] + T[j];
            for(ll k = 0;k < N;k++){
                for(ll l = m;l < m + 5;l++){
                    if(ss[a.substr(k,l)] != 0) c++;
                }
            }
            if(C < c){
                C = c;
                A = T[j];
            }
        }
        string a = A + A;
        for(ll k = 0;k < N;k++){
            for(ll l = m;l < m + 5;l++){
                if(ss[a.substr(k,l)] != 0) ss[a.substr(k,l)] = 0;
            }
        }
        ans[i] = A;
    }
    for(ll i = 0;i < N;i++) cout << ans[i] << endl;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
int main(){
    int N,Q;
    cin >> N >> Q;
    vector<unsigned long long> A(N);
    vector<unsigned long long> low(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        low[i]=A[i]-i-1;
    }

    vector<unsigned long long> K(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> K[i];
        if (low[N-1]<K[i])
        {
            K[i]+=N;
        }else{
            int idx = lower_bound(low.begin(),low.end(),K[i])-low.begin();
            K[i] +=idx;
        }
        cout << K[i] << endl;
    }
    


    return 0;
}