#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
  }
  long long t;
  cin >> t;
  while (t--) {
    long long q;
    cin >> q;
    q--;
    cout << a[q % n] << b[q % m] << endl;
  }
}
