#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long gcd, masks, mask, i, h, d, q, l, r, j, k, n, x, y, z, x1, y1, p, x2,
      y2, m, root, t, sum, size, ind;
  cin >> n >> m;
  string s1[n], s2[m];
  for (int i = 0; i < n; i++) cin >> s1[i];
  for (int i = 0; i < m; i++) cin >> s2[i];
  cin >> q;
  while (q--) {
    cin >> p;
    p--;
    cout << s1[p % n] << s2[p % m] << "\n";
  }
  return 0;
}
