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