#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, n, test_case, m, r;
  test_case = 1;
  while (test_case--) {
    cin >> n >> m;
    string str1[n];
    string str2[m];
    for (i = 0; i < n; i++) {
      cin >> str1[i];
    }
    for (i = 0; i < m; i++) {
      cin >> str2[i];
    }
    vector<pair<int, int> > vec;
    for (i = 0; i < n * m; i++) {
      vec.push_back({i % n, i % m});
    }
    int q;
    cin >> q;
    while (q--) {
      cin >> j;
      j = (j - 1) % (n * m);
      if (j < 0) j += (n * m);
      cout << str1[vec[j].first] << str2[vec[j].second] << "\n";
    }
  }
  return 0;
}
