#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e2;
long long n, m, q, x;
string a[MAXN], b[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) cin >> b[i];
  cin >> q;
  while (q--) {
    cin >> x;
    long long A = x % n, B = x % m;
    cout << a[A == 0 ? n : A] << b[B == 0 ? m : B] << '\n';
  }
}
