#include <bits/stdc++.h>
using namespace std;
int n, m, T;
string a[25], b[25];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  a[0] = a[n];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  b[0] = b[m];
  scanf("%d", &T);
  for (int t = 1; t <= T; ++t) {
    int x;
    scanf("%d", &x);
    cout << a[x % n] + b[x % m] << endl;
  }
  return 0;
}
