#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<string> s(n), t(m);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int j = 0; j < m; ++j) {
    cin >> t[j];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int y;
    cin >> y;
    cout << s[(y - 1) % n] + t[(y - 1) % m] << "\n";
  }
  return 0;
}
