#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int q;
  cin >> q;
  vector<int> vc(q);
  for (int i = 0; i < q; i++) cin >> vc[i];
  for (int i = 0; i < q; i++) {
    cout << a[(vc[i] - 1) % n] + b[(vc[i] - 1) % m] << endl;
  }
}
