#include <bits/stdc++.h>
using namespace std;
string s[25], t[25];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) cin >> s[i];
  for (int i = 0; i <= m - 1; i++) cin >> t[i];
  int q;
  cin >> q;
  while (q--) {
    long long int y;
    cin >> y;
    y--;
    cout << s[y % n] + t[y % m];
    cout << "\n";
  }
  return 0;
}
