#include <bits/stdc++.h>
using namespace std;
long long power_mod(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1)
    return (num * power_mod((num * num) % 1000000007, g / 2)) % 1000000007;
  return power_mod((num * num) % 1000000007, g / 2);
}
long long power(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1) return (num * power((num * num), g / 2));
  return power((num * num), g / 2);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string s[n], t[m];
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  long long q;
  cin >> q;
  while (q--) {
    long long z;
    cin >> z;
    z--;
    cout << s[z % n] << t[z % m] << endl;
  }
  return 0;
}
