#include <bits/stdc++.h>
using namespace std;
int n, m;
string s1[22], s2[22];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> s2[i];
  }
  int tc;
  cin >> tc;
  while (tc--) {
    int x;
    cin >> x;
    x--;
    cout << s1[x % n] + s2[x % m] << endl;
  }
  return 0;
}
