#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> a, b;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    a.push_back(s);
  }
  for (int i = 0; i < m; ++i) {
    string s;
    cin >> s;
    b.push_back(s);
  }
  int q;
  cin >> q;
  while (q--) {
    int y;
    cin >> y;
    y %= (int)(a.size() * b.size());
    if (y == 0) y = a.size() * b.size();
    int l = 0, r = 0, cnt = 0;
    while (cnt != y) {
      if (l >= n) l = 0;
      if (r >= m) r = 0;
      ++cnt;
      if (cnt == y) {
        cout << a[l] << b[r] << '\n';
        break;
      }
      ++l, ++r;
    }
  }
}
