#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q, k;
  cin >> n >> m;
  char a[n + 1][11], b[m + 1][11];
  for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
  for (long long int i = 0; i <= m - 1; i++) cin >> b[i];
  cin >> q;
  for (long long int i = 0; i <= q - 1; i++) {
    cin >> k;
    k--;
    cout << a[k % n] << b[k % m] << endl;
  }
  return 0;
}
