#include <bits/stdc++.h>
using namespace std;
long long int a[101][101];
void solve() {
  long long int n, m, i, j, q, c = 0;
  cin >> n >> m;
  vector<string> S, T;
  string s, t;
  for (i = 0; i < n; i++) {
    cin >> s;
    S.push_back(s);
  }
  for (i = 0; i < m; i++) {
    cin >> s;
    T.push_back(s);
  }
  vector<string> v;
  v.push_back("1");
  s = "1";
  v.push_back(S[0] + T[0]);
  i = 1, j = 1;
  c = 1;
  while (c != n * m) {
    if (i == S.size()) i = 0;
    if (j == T.size()) j = 0;
    s = S[i] + T[j];
    v.push_back(s);
    i++;
    j++;
    c++;
  }
  cin >> q;
  while (q--) {
    long long int y;
    cin >> y;
    if (y % (n * m) == 0)
      cout << v[v.size() - 1] << endl;
    else
      cout << v[y % (n * m)] << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  cerr << "\nTime elapsed: " << setprecision(5)
       << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
