#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int q, x;
  cin >> n >> m;
  vector<string> vn, vm;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    vn.push_back(s);
  }
  for (int i = 0; i < m; i++) {
    cin >> s;
    vm.push_back(s);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int c = 0, j1, j2;
    cin >> x;
    int y1, y2;
    y1 = x % vn.size();
    y2 = x % vm.size();
    if (y1 == 0) y1 = vn.size();
    if (y2 == 0) y2 = vm.size();
    string q;
    q = vn[y1 - 1] + vm[y2 - 1];
    cout << q << "\n";
  }
}
