#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string *a1;
  string *a2;
  a1 = new string[n];
  a2 = new string[m];
  for (int i = 0; i < n; i++) {
    cin >> a1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a2[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int y;
    cin >> y;
    y--;
    cout << a1[y % n] + a2[y % m] << endl;
  }
  delete[] a1;
  delete[] a2;
  return 0;
}
