#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[21][11], b[21][11];
  int n, m, q, x;
  cin >> n >> m;
  for (int i = (0); i < (n); ++i) scanf("%s", a[i]);
  for (int i = (0); i < (m); ++i) scanf("%s", b[i]);
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    cin >> x;
    x--;
    printf("%s%s\n", a[x % n], b[x % m]);
  }
  return 0;
}
