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