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