#include <bits/stdc++.h>
using namespace std;
const int e = 1e6;
string s[e], t[e], k, d;
string vovan;
string s1[e], s2[e];
long long dem = 1, dem1 = 1;
long long m, n, q, l;
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> s[i % n];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> t[i % m];
  }
  cin >> q;
  for (long long i = 1; i <= n * m; i++) {
    s1[i] = s[i % n];
    s2[i] = t[i % m];
  }
  while (q--) {
    cin >> l;
    if (l % n == 0) {
      cout << s1[n];
      if (l % m == 0) {
        cout << s2[m];
      } else {
        cout << s2[l % m];
      }
      cout << endl;
    } else if (l % m == 0) {
      if (l % n == 0) {
        cout << s1[n];
      } else {
        cout << s1[l % n];
      }
      cout << s2[m];
      cout << endl;
    } else {
      cout << s1[(l % n)] << s2[l % m] << endl;
    }
  }
}
