#include <bits/stdc++.h>
using namespace std;
int m, n, q, q1, i;
string a[100005], b[100005];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
  }
  cin >> q1;
  while (q1--) {
    cin >> q;
    int q2, q3;
    q2 = q % n;
    q3 = q % m;
    if (q3 == 0 && q2 == 0) {
      cout << a[n] << b[m] << endl;
    } else if (q2 != 0 && q3 == 0) {
      cout << a[q2] << b[m] << endl;
    } else if (q2 == 0 && q3 != 0) {
      cout << a[n] << b[q3] << endl;
    } else if (q3 != 0 && q2 != 0) {
      cout << a[q2] << b[q3] << endl;
    }
  }
}
