#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> first(n);
  vector<string> second(m);
  for (int i = 0; i < n; ++i) {
    cin >> first[i];
  }
  for (int j = 0; j < m; ++j) {
    cin >> second[j];
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int a;
    cin >> a;
    --a;
    cout << first[a % n] + second[a % m] << '\n';
  }
  return 0;
}
