#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, h, i;
  cin >> n >> m;
  string s1[n], s2[m], s3;
  for (i = 0; i < n; i++) {
    cin >> s1[i];
  }
  for (i = 0; i < m; i++) {
    cin >> s2[i];
  }
  cin >> k;
  while (k--) {
    cin >> h;
    for (i = 0; i < n; i++) {
      s3 = s1[(h - 1) % n] + s2[(h - 1) % m];
    }
    cout << s3 << "\n";
  }
  return 0;
}
