#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s1[n], s2[m];
  for (int i = 0; i < n; i++) {
    cin >> s1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> s2[i];
  }
  int c;
  cin >> c;
  for (int i = 0; i < c; i++) {
    long long int k;
    cin >> k;
    if (k % n == 0 && k % m == 0) {
      cout << s1[n - 1] + s2[m - 1] << endl;
    } else if (k % n == 0) {
      cout << s1[n - 1] + s2[(k % m) - 1] << endl;
    } else if (k % m == 0) {
      cout << s1[(k % n) - 1] + s2[m - 1] << endl;
    } else {
      cout << s1[(k % n) - 1] + s2[(k % m) - 1] << endl;
    }
  }
  return EXIT_SUCCESS;
}
