#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, t, x, y, n, s = 0, c = 0, c1 = 0, x1;
  cin >> x >> y;
  char a[x][11], b[y][11];
  for (i = 1; i < x; i++) cin >> a[i];
  cin >> a[0];
  for (i = 1; i < y; i++) cin >> b[i];
  cin >> b[0];
  cin >> t;
  while (t--) {
    cin >> n;
    cout << a[n % x] << b[n % y] << endl;
  }
}
