#include <bits/stdc++.h>
const long long M = 1e9 + 7;
using namespace std;
void solve() {
  long long n, m, q;
  cin >> n >> m;
  string s1[n], s2[m];
  for (long long i = 0; i < n; i++) cin >> s1[i];
  for (long long i = 0; i < m; i++) cin >> s2[i];
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long x;
    cin >> x;
    cout << s1[(x - 1) % n] << s2[(x - 1) % m] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
