#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<string> v, vec;
  for (long long i = 1; i <= n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  for (long long i = 1; i <= m; i++) {
    string s;
    cin >> s;
    vec.push_back(s);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a;
    cin >> a;
    long long u = a % v.size();
    cout << v[(u - 1 + v.size()) % v.size()];
    u = a % vec.size();
    cout << vec[(u - 1 + vec.size()) % vec.size()];
    cout << endl;
  }
}
