#include <bits/stdc++.h>
using namespace std;
void doit() {}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> as, bs;
  for (int i = 0; i < n; ++i) {
    string x;
    cin >> x;
    as.push_back(x);
  }
  for (int i = 0; i < m; ++i) {
    string x;
    cin >> x;
    bs.push_back(x);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    uint64_t y;
    cin >> y;
    --y;
    cout << as[y % n] << bs[y % m] << endl;
  }
  return 0;
}
