#include <bits/stdc++.h>
void readInput(unsigned short int& n, unsigned short int& m, std::string s[],
               std::string t[], unsigned short int& q, unsigned int y[]) {
  std::cin >> n >> m;
  for (unsigned short int index = 0; index < n; index++) std::cin >> s[index];
  for (unsigned short int index = 0; index < m; index++) std::cin >> t[index];
  std::cin >> q;
  for (unsigned short int index = 0; index < q; index++) std::cin >> y[index];
}
void solveProblem(unsigned short int n, unsigned short int m, std::string s[],
                  std::string t[], unsigned short int q, unsigned int y[]) {
  for (unsigned short int index = 0; index < q; index++) {
    unsigned int year = y[index];
    std::string nameOfYear = s[(year - 1) % n] + t[(year - 1) % m];
    std::cout << nameOfYear << '\n';
  }
}
int main() {
  unsigned short int n, m;
  std::string s[20], t[20];
  unsigned short int q;
  unsigned int y[2021];
  readInput(n, m, s, t, q, y);
  solveProblem(n, m, s, t, q, y);
  return 0;
}
