#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, m;
  cin >> n >> m;
  char s[21][21];
  char s1[21][21];
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (j = 1; j <= m; j++) {
    cin >> s1[j];
  }
  int p, y;
  cin >> p;
  while (p--) {
    string str;
    cin >> y;
    int a, b;
    a = y % n;
    if (a == 0) {
      a = a + n;
    }
    b = y % m;
    if (b == 0) {
      b = b + m;
    }
    cout << s[a] << s1[b] << "\n";
  }
  return 0;
}
