#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ns[20];
  string mt[20];
  for (int i = 1; i <= n; i++) {
    cin >> ns[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> mt[i];
  }
  int cases;
  cin >> cases;
  while (cases--) {
    int number;
    cin >> number;
    string ab = "";
    int first = number % n == 0 ? n : number % n;
    int second = number % m == 0 ? m : number % m;
    ab += ns[first];
    ab += mt[second];
    cout << ab << endl;
  }
  return 0;
}
