#include <bits/stdc++.h>
using namespace std;
int main() {
  string strx[25], stry[25], str[500];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> strx[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> stry[i];
  }
  int sz = m * n;
  int j = 0, k = 0;
  for (int i = 1; i <= sz; i++) {
    str[i] = strx[j] + stry[k];
    j++;
    k++;
    if (j == n) j = 0;
    if (k == m) k = 0;
  }
  int q;
  cin >> q;
  while (q--) {
    int nn, temp;
    cin >> nn;
    temp = nn % sz;
    if (temp == 0)
      cout << str[sz] << endl;
    else
      cout << str[temp] << endl;
  }
  return 0;
}
