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