#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  string t[m];
  for (int i = 0; i < m; i++) cin >> t[i];
  cin >> q;
  int year;
  while (q--) {
    cin >> year;
    cout << s[(year - 1) % n] + t[(year - 1) % m] << '\n';
  }
  return 0;
}
