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