#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << ' : ' << arg1 << ' | ';
  __f(comma + 1, args...);
}
bool findfxn(string a, string b) {
  size_t found = a.find(b);
  if (found != string::npos)
    return 1;
  else
    return 0;
}
long long int power(long long int a, long long int b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    return power(a * a, b / 2);
  } else {
    return a * power(a * a, (b - 1) / 2);
  }
}
void solve() {
  long long int n, m, q, y;
  cin >> n >> m;
  vector<string> s, t;
  string tmp;
  for (int i = 0; i < (n); i++) {
    cin >> tmp;
    s.push_back(tmp);
  }
  for (int i = 0; i < (m); i++) {
    cin >> tmp;
    t.push_back(tmp);
  }
  cin >> q;
  for (int i = 0; i < (q); i++) {
    cin >> y;
    if (y % n)
      cout << s[y % n - 1];
    else
      cout << s[n - 1];
    if (y % m)
      cout << t[y % m - 1] << endl;
    else
      cout << t[m - 1] << endl;
  }
  return;
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) solve();
  return 0;
  return 0;
}
