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