#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b;
  string s1[22], s2[22];
  for (int i = 0; i < a; i++) {
    cin >> s1[i];
  }
  for (int j = 0; j < b; j++) {
    cin >> s2[j];
  }
  int t;
  cin >> t;
  while (t--) {
    cin >> c;
    c--;
    cout << s1[c % a] + s2[c % b] << endl;
  }
}
