#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;

template <typename T>
struct BIT {
    vector<T> bit;
    // 単位元
    const T neutral = 0;
    // 要素数
    int n;
    BIT(int n_ = 1e5) { init(n_); }
    void init(int sz) {
        n=1; while(n < sz) n*=2;
        bit.assign(n+1, neutral);
    }
    void update(int i, T w) {
        for(int x=i+1; x<(ll)bit.size(); x += x&-x) bit[x] += w;
    }
    // [0,i]
    T query(int i) {
        T ret = neutral;
        for(int x=i+1; x>0; x -= x&-x) ret += bit[x];
        return ret;
    }
};

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll h, w;
    cin >> h >> w;
    vector<ll> a(h), b(w);
    vector<string> as(h), bs(w);
    REP(i, h) cin >> a[i], as[i] = to_string(a[i]);
    REP(i, w) cin >> b[i], bs[i] = to_string(b[i]);
    ll q;
    cin >> q;
    vector<ll> d(q);
    REP(i, q) cin >> d[i];

    auto length = [](ll x) {
        ll l = 0;
        while(x > 0) x /= 10, l++;
        return l;
    };
    ll sum = 0;
    vector<ll> a_len(h), b_len(w);
    REP(i, h) a_len[i] = length(a[i]);
    REP(i, w) b_len[i] = length(b[i]), sum += b_len[i];

    vector<pair<string,ll>> b_sorted(w);
    REP(i, w) b_sorted[i] = make_pair(bs[i], i);
    sort(ALL(b_sorted));
    vector<ll> len(h);
    REP(i, h) {
        auto check = [&](ll mid) {
            // a[i]の指数部 + b[mid]の指数部 < a[i]b[mid]の指数部
            ll idx = b_sorted[mid].second;
            return a_len[i]-1 + b_len[idx]-1 < length(a[i]*b[idx])-1;
        };
        ll lb = -1, ub = w;
        while(ub-lb>1) {
            ll mid = (lb+ub)/2;
            if(check(mid)) ub = mid;
            else lb = mid;
        }
        // i行目目の長さ
        len[i] = (a_len[i]-1)*w + (sum-w) + w + w-ub;
    }

    vector<ll> len_rui(len);
    FOR(i, 1, h) len_rui[i] += len_rui[i-1];
    string ans(q, 'x');
    vector<vector<PII>> query(h);
    REP(i, q) {
        // d[i] が何行目なのか？
        ll row = lower_bound(ALL(len_rui), d[i]) - len_rui.begin();
        if(row >= h) continue;
        query[row].push_back({d[i]-(row==0?0:len_rui[row-1]), i});
    }

    // a[i]を仮数部でソートする
    vector<ll> ord(h);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](ll l, ll r){
        return as[l] < as[r];
    });

    ll idx = w-1;
    BIT<ll> bit(w);
    REP(i, w) bit.update(i, b_len[i]);
    auto func = [&](ll aidx, ll bidx) {
        return a_len[aidx]-1 + b_len[bidx]-1 < length(a[aidx]*b[bidx])-1;
    };
    while(idx>=0 && func(ord[0], b_sorted[idx].second)) {
        bit.update(b_sorted[idx].second, 1);
        idx--;
    }
    REP(ii, ord.size()) {
        ll i = ord[ii];
        for(auto p: query[i]) {
            // p.first 文字目がなにか？
            // (i,ub)に存在する
            auto check = [&](ll mid) {
                return bit.query(mid) + (mid+1)*(a_len[i]-1) >= p.first;
            };
            ll lb=-1, ub=w-1;
            while(ub-lb>1) {
                ll mid = (lb+ub)/2;
                if(check(mid)) ub = mid;
                else lb = mid;
            }
            // (i,ub)のd文字目
            if(ub >= 0) p.first -= bit.query(ub-1) + ub*(a_len[i]-1);
            ans[p.second] = to_string(a[i] * b[ub])[p.first-1];
        }

        if(ii+1 == (ll)ord.size()) continue;
        ll nxti = ord[ii+1];
        while(idx>=0 && func(nxti, b_sorted[idx].second)) {
            bit.update(b_sorted[idx].second, 1);
            idx--;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 34164