#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (auto &x : s) {
    cin >> x;
  }
  vector<string> t(m);
  for (auto &x : t) {
    cin >> x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int y;
    cin >> y;
    --y;
    cout << s[y % n] << t[y % m] << "\n";
  }
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  solve();
}
