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