#include <bits/stdc++.h>
using namespace std;
ifstream fin("template.in");
ofstream fout("template.out");
int main() {
  int n, m;
  cin >> n >> m;
  string ar1[n], ar2[m];
  for (long long i = 0; i < n; i++) {
    cin >> ar1[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> ar2[i];
  }
  int q;
  cin >> q;
  int in;
  for (int i = 0; i < q; i++) {
    cin >> in;
    in--;
    cout << ar1[in % n] << ar2[in % m] << endl;
  }
}
