#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<string> vec1, vec2;
  string temp;
  for (long long int i = 0; i < n; i++) {
    cin >> temp;
    vec1.push_back(temp);
  }
  for (long long int i = 0; i < m; i++) {
    cin >> temp;
    vec2.push_back(temp);
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int year;
    cin >> year;
    long long int a = year % n;
    if (a == 0) a = n;
    long long int b = year % m;
    if (b == 0) b = m;
    string ans = "";
    ans += vec1[a - 1];
    ans += vec2[b - 1];
    cout << ans << "\n";
  }
  return 0;
}
