#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

template<typename T> void drop(T x){cout<<x<<endl;exit(0);};

template<typename T, typename E>
struct SegmentTree{
  using F = function<T(T ,T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;

  Int n, height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;

  SegmentTree(F f, G g, H h, T ti, E ei):
    f(f), g(g), h(h), ti(ti), ei(ei){}

  void init(Int n_){
    n = 1; height = 0;
    while(n < n_) n<<=1, height++;
    dat.assign(2*n, ti);
    laz.assign(2*n, ei);
  }

  void build(const vector<T> &v){
    Int n_ = v.size();
    init(n_);
    for(Int i=0;i<n_;i++) dat[n+i] = v[i];
    for(Int i=n-1;i;i--)
      dat[i] = f(dat[(i<<1)|0], dat[(i<<1)|1]);
  }

  inline T reflect(Int k){
    return laz[k] == ei? dat[k]:g(dat[k], laz[k]);
  }

  inline void eval(Int k){
    if(laz[k] == ei) return;
    laz[(k<<1)|0] = h(laz[(k<<1)|0], laz[k]);
    laz[(k<<1)|1] = h(laz[(k<<1)|1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }

  inline void thrust(Int k){
    for(Int i=height;i;i--) eval(k>>i);
  }

  inline void recalc(Int k){
    while(k>>=1)
      dat[k] = f(reflect((k<<1)|0), reflect((k<<1)|1));
  }

  void update(Int a, Int b, E x){
    thrust(a += n);
    thrust(b += n-1);
    for(Int l=a, r=b+1;l<r;l>>=1, r>>=1){
      if(l&1) laz[l] = h(laz[l], x), l++;
      if(r&1) --r, laz[r] = h(laz[r], x);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(Int a, T x){
    thrust(a += n);
    dat[a] = x; laz[a] = ei;
    recalc(a);
  }

  T query(Int a, Int b){
    thrust(a += n);
    thrust(b += n-1);
    T vl = ti, vr = ti;
    for(Int l=a, r=b+1;l<r;l>>=1, r>>=1){
      if(l&1) vl = f(vl, reflect(l++));
      if(r&1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }

  template<typename C>
  Int find(Int st, C &check, T &acc, Int k, Int l, Int r){
    if(l + 1 == r){
      acc = f(acc, reflect(k));
      return check(acc)? k-n:-1;
    }
    eval(k);
    Int m = (l+r)>>1;
    if(m<=st) return find(st, check, acc, (k<<1)|1, m, r);

    if(st <= l && !check(f(acc, dat[k]))){
      acc = f(acc, dat[k]);
      return -1;
    }

    Int vl = find(st, check, acc, (k<<1)|0, l, m);
    if(~vl) return vl;
    return find(st, check, acc, (k<<1)|1, m, r);
  }

  template<typename C>
  Int find(Int st, C &check){
    T acc = ti;
    return find(st, check, acc, 1, 0, n);
  }
};


const Int MAX = 1e5+100;
Int dp[20][MAX];

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

  Int n,m;
  cin>>n>>m;
  vector<Int> as(n),bs(m);
  for(Int i=0;i<n;i++) cin>>as[i];
  for(Int i=0;i<m;i++) cin>>bs[i];

  Int q;
  cin>>q;
  vector<Int> ds(q);
  for(Int i=0;i<q;i++) cin>>ds[i];

  string ans(q,'x');

  vector<Int> ss(bs);
  sort(ss.begin(),ss.end());

  for(Int i=0;i<n;i++){
    Int po=1;
    for(Int j=0;j<19;j++){
      auto pred=[&](Int x){return as[i]*x<po;};
      Int L=-1,R=m;
      while(L+1<R){
        Int M=(L+R)>>1;
        if(pred(ss[M])) L=M;
        else R=M;
      }
      dp[j][i]=R;
      if(j<18) po*=10;
    }

    dp[19][i]=m;
  }

  vector<Int> sm(n+1,0);
  for(Int i=0;i<n;i++){
    Int res=0;
    for(Int j=1;j<20;j++)
      res+=(dp[j][i]-dp[j-1][i])*j;
    sm[i+1]=sm[i]+res;
  }

  // sm[k] <= ds[i]
  vector< vector<Int> > I(n+2);
  for(Int i=0;i<q;i++){
    ds[i]--;
    Int k=upper_bound(sm.begin(),sm.end(),ds[i])-sm.begin()-1;
    //cout<<k<<endl;
    I[k].emplace_back(i);
  }

  using P = pair<Int, Int>;
  vector<P> vp,vq;
  for(Int i=0;i<n;i++) vp.emplace_back(as[i],i);
  for(Int i=0;i<m;i++) vq.emplace_back(bs[i],i);
  sort(vp.begin(),vp.end());
  sort(vq.rbegin(),vq.rend());

  auto f=[&](Int a,Int b){return a+b;};
  SegmentTree<Int, Int> seg(f,f,f,0,0);
  seg.build(vector<Int>(m+1,1));

  vector<Int> pos(20,0);
  for(Int i=0;i<n;i++){
    Int k=vp[i].second;

    Int po=10;
    for(Int j=1;j<19;j++){
      while((pos[j]<m)&&(vq[pos[j]].first*as[k]>=po)){
        Int q=vq[pos[j]].second;
        seg.set_val(q,j+1);
        pos[j]++;
      }
      if(j<18) po*=10;
    }

    for(Int j:I[k]){
      Int d=ds[j]-sm[k];
      // [0, p) <= d
      // [0, p] > d
      auto check=[&](Int s){return s>d;};
      Int p=seg.find(0,check);
      Int r=seg.query(0,p);
      assert(seg.query(0,p+0)<=d);
      assert(seg.query(0,p+1)> d);
      //cout<<d<<" "<<seg.query(0,p)<<" "<<seg.query(0,p+1)<<endl;
      d-=r;
      //cout<<j<<" "<<d<<":"<<to_string(as[k]*bs[p])<<endl;
      ans[j]=to_string(as[k]*bs[p])[d];
    }
  }

  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 39572