#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> mp;
  int n, m;
  cin >> n >> m;
  vector<string> v1, v2;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v1.push_back(s);
  }
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    v2.push_back(s);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a;
    cin >> a;
    cout << v1[(a - 1) % n] << v2[(a - 1) % m] << endl;
  }
  return 0;
}
