#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[n], t[m];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> t[i];
  }
  int q;
  cin >> q;
  long long y[q];
  for (int i = 0; i < q; ++i) {
    cin >> y[i];
  }
  string ans[q];
  for (int i = 0; i < q; ++i) {
    ans[i] = s[(y[i] - 1) % n] + t[(y[i] - 1) % m];
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
