#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q, y, i;
  cin >> n >> m;
  string a[100000], b[100000];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  cin >> q;
  while (q--) {
    cin >> y;
    y--;
    int ix, iy;
    ix = y % n;
    iy = y % m;
    cout << a[ix] << b[iy] << endl;
  }
}
