#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int i = 0;
  cin >> n >> m;
  string a[n];
  string b[m];
  while (i < n) {
    cin >> a[i];
    i++;
  }
  i = 0;
  while (i < m) {
    cin >> b[i];
    i++;
  }
  int q;
  cin >> q;
  while (q--) {
    int y, s, t;
    cin >> y;
    s = (y - 1) % n;
    t = (y - 1) % m;
    cout << a[s] << b[t] << "\n";
  }
}
