#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, m;
  vector<string> v, s;
  cin >> a >> b;
  string q;
  for (int j = 0; j < a; j++) {
    cin >> q;
    v.push_back(q);
  }
  for (int j = 0; j < b; j++) {
    cin >> q;
    s.push_back(q);
  }
  cin >> c;
  for (int j = 0; j < c; j++) {
    cin >> d;
    m = d;
    d = d - 1;
    if (d >= v.size()) {
      d = d % v.size();
      cout << v[d];
    } else
      cout << v[d];
    m = m - 1;
    if (m >= s.size()) {
      m = m % s.size();
      cout << s[m];
    } else
      cout << s[m];
    cout << endl;
  }
}
