#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
static constexpr int INF = (int)1e9;
static constexpr ll INFL = (ll)1e18;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> s(n), t(m);
  for (auto& si : s) cin >> si;
  for (auto& ti : t) cin >> ti;
  int q, y;
  cin >> q;
  while (q--) cin >> y, --y, cout << s[y % n] << t[y % m] << '\n';
  return 0;
}
