#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, q, arr;
  cin >> n >> m;
  string str[n], str2[m];
  for (i = 0; i < n; i++) cin >> str[i];
  for (i = 0; i < m; i++) cin >> str2[i];
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> arr;
    cout << str[(arr - 1) % n] << str2[(arr - 1) % m] << endl;
  }
  return 0;
}
