#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, a, b;
  char k[20][11], y[20][11];
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> k[i];
  for (i = 0; i < m; i++) cin >> y[i];
  cin >> a;
  for (i = 0; i < a; i++) {
    cin >> b;
    cout << k[(b - 1) % n] << y[(b - 1) % m] << endl;
  }
  return 0;
}
