#include <bits/stdc++.h>
using namespace std;
int main() {
  const int N = 20;
  int n, m, tc, year;
  cin >> n >> m;
  string s[N], t[N];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  cin >> tc;
  while (tc--) {
    cin >> year;
    year--;
    cout << s[year % n] << t[year % m] << endl;
  }
  return 0;
}
