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