#include <bits/stdc++.h>
using namespace std;
int main() {
  int first_name_len, second_name_len;
  cin >> first_name_len >> second_name_len;
  string first_names[first_name_len], second_names[second_name_len];
  for (int i = 0; i < first_name_len; i++) {
    cin >> first_names[i];
  }
  for (int i = 0; i < second_name_len; i++) {
    cin >> second_names[i];
  }
  int queries;
  cin >> queries;
  while (queries--) {
    int year;
    cin >> year;
    string year_name = "";
    if (year % first_name_len != 0) {
      year_name += first_names[year % first_name_len - 1];
    } else {
      year_name += first_names[first_name_len - 1];
    }
    if (year % second_name_len != 0) {
      year_name += second_names[year % second_name_len - 1];
    } else {
      year_name += second_names[second_name_len - 1];
    }
    cout << year_name << endl;
  }
  return 0;
}
