#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  string s1[n], s2[m];
  for (int i = 0; i < n; i++) cin >> s1[i];
  for (int j = 0; j < m; j++) cin >> s2[j];
  long long q;
  cin >> q;
  while (q--) {
    long long y;
    cin >> y;
    long long a, b;
    string s3;
    a = (y - 1) % n;
    b = (y - 1) % m;
    s3 = s1[a] + s2[b];
    cout << s3 << endl;
  }
  return 0;
}
