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