#include <bits/stdc++.h>
using namespace std;
template <typename T>
T MAX(T a, T b) {
  return (a > b) ? a : b;
}
template <typename T>
T MIN(T a, T b) {
  return (a < b) ? a : b;
}
template <typename T>
void UMAX(T &a, T b) {
  a = (a > b ? a : b);
}
template <typename T>
void UMIN(T &a, T b) {
  a = (a < b ? a : b);
}
int readint() {
  char c = getchar();
  int ret = 0;
  while (!(c >= '0' && c <= '9')) c = getchar();
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}
void putint(int v) {
  if (!v) {
    putchar('0');
    return;
  }
  if (v >= 10) putint(v / 10);
  putchar('0' + (v % 10));
}
int n, m;
string s[25], t[25];
int main() {
  int i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (i = 0; i < m; ++i) {
    cin >> t[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int y;
    cin >> y;
    cout << s[(y - 1) % n] << t[(y - 1) % m] << endl;
  }
  return 0;
}
