#include <bits/stdc++.h>
using namespace std;
int n, m, q, y;
vector<string> a;
vector<string> b;
string s;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    a.push_back(s);
  }
  for (int i = 0; i < m; i++) {
    cin >> s;
    b.push_back(s);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> y;
    if (y % n == 0)
      cout << a[n - 1];
    else
      cout << a[y % n - 1];
    if (y % m == 0)
      cout << b[m - 1];
    else
      cout << b[y % m - 1];
    cout << endl;
  }
}
