#include <bits/stdc++.h>
using namespace std;
string s[35], t[35];
int main() {
  int n, m, ask, y;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> t[i];
  scanf("%d", &ask);
  while (ask--) {
    scanf("%d", &y);
    cout << s[(y - 1 + n) % n + 1] << t[(y - 1 + m) % m + 1] << endl;
  }
  return 0;
}
