#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using _loop_int = int;
const ll MOD = 1000000007ll;
int n, m;
char s[25][12];
char t[25][12];
int main() {
  scanf("%d%d", &n, &m);
  for (_loop_int i = 0; i < (_loop_int)(n); i++) scanf("%s", s[i]);
  for (_loop_int i = 0; i < (_loop_int)(m); i++) scanf("%s", t[i]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int y;
    scanf("%d", &y);
    y--;
    printf("%s%s\n", s[y % n], t[y % m]);
  }
  return 0;
}
