#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q;
  cin >> n >> m;
  string s[n + 1], t[m + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> s[i];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> t[i];
  }
  cin >> q;
  long long int y[q + 1];
  for (int i = 1; i < q + 1; i++) {
    cin >> y[i];
  }
  for (int i = 1; i < q + 1; i++) {
    int temp = y[i] % (n * m);
    int x1 = y[i] % n;
    int x2 = y[i] % m;
    if (x1 == 0) {
      x1 = x1 + n;
    }
    if (x2 == 0) {
      x2 = x2 + m;
    }
    string answer = s[x1] + t[x2];
    cout << answer << "\n";
  }
}
