#include <bits/stdc++.h>
using namespace std;
char s[20][20], t[20][20];
void solve() {
  int n, m, q, u;
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < m; i++) scanf("%s", t[i]);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &u);
    u--;
    cout << s[u % n] << t[u % m] << endl;
  }
}
int main() {
  solve();
  return 0;
}
