#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int val = n * m;
  vector<string> first(n, "");
  vector<string> second(m, "");
  for (int i = 0; i < n; i++) {
    cin >> first[i];
  }
  for (int i = 0; i < m; i++) cin >> second[i];
  vector<string> precomp(n * m, "");
  for (int i = 0; i < n * m; i++) {
    precomp[i] = first[i % n] + second[i % m];
  }
  int queries;
  cin >> queries;
  while (queries--) {
    int input;
    cin >> input;
    int remainder = (input - 1) % val;
    cout << precomp[remainder] << endl;
  }
  return 0;
}
