#include <bits/stdc++.h>
using namespace std;
long long i, j, sum = 0, c = 0, ctr = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, q, year;
  char s[21][11], ss[20][11];
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < m; i++) cin >> ss[i];
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> year;
    printf("%s%s\n", s[(year - 1) % n], ss[(year - 1) % m]);
  }
  return 0;
}
