#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q;
  long long y;
  cin >> n >> m;
  vector<string> s(n);
  vector<string> t(m);
  for (string &i : s) cin >> i;
  for (string &i : t) cin >> i;
  cin >> q;
  while (q) {
    --q;
    cin >> y;
    cout << s[(y - 1) % n] + t[(y - 1) % m] << endl;
  }
  return 0;
}
