#include <bits/stdc++.h>
int main() {
  int n, m, q;
  scanf("%d %d", &n, &m);
  char s[n][11];
  char t[m][11];
  for (int i = 0; i < n; i++) scanf("%s", &s[i]);
  for (int i = 0; i < m; i++) scanf("%s", &t[i]);
  scanf("%d", &q);
  char ans[q][44];
  char ans1[22];
  char ans2[11];
  int year[q];
  for (int i = 0; i < q; i++) {
    scanf("%d", &year[i]);
    if (year[i] % n == 0) {
      strcpy(ans1, s[n - 1]);
    } else {
      strcpy(ans1, s[(year[i] % n) - 1]);
    }
    if (year[i] % m == 0) {
      strcpy(ans2, t[m - 1]);
    } else {
      strcpy(ans2, t[(year[i] % m) - 1]);
    }
    strcat(ans1, ans2);
    strcpy(ans[i], ans1);
  }
  for (int i = 0; i < q; i++) {
    printf("%s\n", ans[i]);
  }
}
