#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const long long INF = 1e18;
string a[30], b[30], ans[407];
void rua() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int cnt = 0, s1 = -1, s2 = -1;
  while (cnt < n * m) {
    s1 = (s1 + 1) % n;
    s2 = (s2 + 1) % m;
    ans[cnt++] = a[s1] + b[s2];
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    cout << ans[(x - 1) % (n * m)] << endl;
  }
}
int main() {
  rua();
  return 0;
}
