#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, query, y;
  string t, a, b;
  cin >> n >> m;
  string first[n];
  string second[m];
  for (int i = 0; i < n; i++) {
    cin >> t;
    first[i] = t;
  }
  for (int i = 0; i < m; i++) {
    cin >> t;
    second[i] = t;
  }
  cin >> query;
  while (query--) {
    cin >> y;
    y -= 1;
    a = first[y % n];
    b = second[y % m];
    cout << a << b << '\n';
  }
}
