#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, q, y;
  cin >> n >> m;
  string s1[n], s2[m];
  for (int i = 0; i < n; ++i) cin >> s1[i];
  for (int i = 0; i < m; ++i) cin >> s2[i];
  cin >> q;
  while (q--) {
    cin >> y;
    if (y % n == 0)
      cout << s1[n - 1];
    else
      cout << s1[y % n - 1];
    if (y % m == 0)
      cout << s2[m - 1];
    else
      cout << s2[y % m - 1];
    cout << '\n';
  }
}
