#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

typedef long long ll;

template<typename T>
struct RangeTree {
  vector<vector<T> > dat;
  int segn2, N;

  RangeTree(int n, T *a) : N(n){
    for(segn2 = 1; segn2 < n; segn2 *= 2);
    dat.assign(segn2*2, vector<T>());
    init(a, 0, 0, n);
  }

  void init(T *a, int k, int l, int r){
    if(r - l == 1) {
      dat[k].push_back(a[l]);
    } else {
      int lch = k*2 + 1, rch = k*2 + 2;
      init(a, lch, l, (l+r)/2);
      init(a, rch, (l+r)/2, r);
      dat[k].resize(r - l);

      merge(dat[lch].begin(), dat[lch].end(),
            dat[rch].begin(), dat[rch].end(),
            dat[k].begin());
    }
  }

  //A[i:j-1] の x以下の個数
  int query(int i, int j, T x, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r = N;

    if (j <= l || r <= i)  return 0;

    if (i <= l && r <= j)
      return upper_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin();

    int lc = query(i, j, x, l, (l+r)/2, k*2 + 1);
    int rc = query(i, j, x, (l+r)/2, r, k*2 + 2);
    return lc + rc;
  }
};

int D = 19;

int H, W;
ll a[SIZE], b[SIZE], sb[SIZE], araw[SIZE], braw[SIZE];
ll limit[SIZE][20];

void create(int idx, ll x) {
  ll base = 1;
  for(int i=0; i<D-1; i++) {
    base *= 10;
    limit[idx][i] = (base - 1) / x;
  }

  limit[idx][D-1] = INF;
}


ll sumH[SIZE];
int exp10a[SIZE], exp10b[SIZE];
int exp10bSum[SIZE];

const ll e9 = 1000000000;
const ll e8 = 100000000;

int main() {

  scanf("%d%d", &H, &W);

  for(int i=0; i<H; i++) {
    scanf("%lld", a+i);
    araw[i] = a[i];

    for(ll j=a[i];j>=10;j/=10)
      exp10a[i] += 1;

    if(a[i] == e9) a[i] /= 10;
    while(a[i] * 10 < e9)  a[i] *= 10;
  }

  for(int i=0; i<W; i++) {
    scanf("%lld", b+i);
    braw[i] = b[i];

    for(ll j=b[i];j>=10;j/=10)
      exp10b[i] += 1;

    exp10bSum[i] += exp10b[i];
    exp10bSum[i+1] += exp10bSum[i];

    if(b[i] == e9) b[i] /= 10;
    while(b[i] * 10 < e9)  b[i] *= 10;

    sb[i] = b[i];
    debug(b[i]);
  }

  RangeTree<ll> tree(W, b);

  sort(sb, sb+W);

  for(int i=0; i<H; i++) {
    //create(i, a[i]);
    sumH[i] = 0;

    int limit = (e9 * e8 - 1) / a[i];

    int tmp = W - (upper_bound(sb, sb+W, limit) - sb);
    sumH[i] += tmp + exp10bSum[W] + exp10a[i] * W + W;
  }

  for(int i=0; i<H; i++) {
    debug(sumH[i]);
    sumH[i+1] += sumH[i];
  }

  int Q;

  scanf("%d", &Q);

  string ans = "";

  for(int i=0; i<Q; i++) {
    ll d;

    scanf("%lld", &d);

    if (sumH[H] < d) {
      ans += "x";
      continue;
    }

    int p = lower_bound(sumH, sumH+H, d) - sumH;

    int l = 0, r = W-1;

    ll base = p == 0 ? 0 : sumH[p-1];

    while(l < r) {
      int mid = (l+r)/2;

      int v = (mid+1) * exp10a[p] + exp10bSum[mid] + mid+1;
      int limit = (e9 * e8 - 1) / a[p];

      int tmp = mid+1 - tree.query(0, mid+1, limit);
      v += tmp;

      debug(mid);
      debug(tree.query(0, mid+1, limit));
      debug(limit);
      debug(v);

      if (v + base >= d)
        r = mid;
      else
        l = mid + 1;
    }

    ll v = l * exp10a[p] + (l == 0 ? 0 : exp10bSum[l-1]) + l;
    int limit = (e9 * e8 - 1) / a[p];
    int tmp = l - tree.query(0, l, limit);
    v += tmp;

    int q = l;
    base += v;

    //cerr << "(" << p << ", " << q << ") : " << d-base-1 << endl;

    string value = to_string((ll)araw[p] * braw[q]);
    debug((ll)araw[p] * braw[q]);

    ans += value[d-base-1];
  }

  puts(ans.c_str());

  return 0;
}



Measured memory_bytes: 33136