#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1LL << 60;
const long long INF = 1 << 30;
long long MOD = 1000000007;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<string> S(N), T(M);
  for (long long i = 0; i < (N); i++) cin >> S[i];
  for (long long i = 0; i < (M); i++) cin >> T[i];
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (Q); i++) {
    long long Y;
    cin >> Y;
    Y--;
    cout << S[Y % N] << T[Y % M] << endl;
  }
}
