#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, m, x, q, max = 0, min = 0;
  cin >> n >> m;
  string s[n], t[m];
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < m; i++) cin >> t[i];
  cin >> q;
  while (q--) {
    cin >> x;
    max = x % n;
    min = x % m;
    if (max == 0 && min != 0)
      cout << s[n - 1] << t[min - 1] << endl;
    else if (max != 0 && min == 0)
      cout << s[max - 1] << t[m - 1] << endl;
    else if (max == 0 && min == 0)
      cout << s[n - 1] << t[m - 1] << endl;
    else
      cout << s[max - 1] << t[min - 1] << endl;
  }
}
