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