#include <bits/stdc++.h>
using namespace std;
char l[50][20], r[50][20];
int n, m;
int t;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", l[i]);
  for (int i = 0; i < m; i++) scanf("%s", r[i]);
  scanf("%d", &t);
  while (t--) {
    int x;
    scanf("%d", &x);
    x--;
    printf("%s%s\n", l[x % n], r[x % m]);
  }
  return 0;
}
