#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, a[10000];
  cin >> n;
  cin >> m;
  string s[1000], f[1000];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> f[i];
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < k; i++) {
    a[i]--;
    cout << s[a[i] % n] << f[a[i] % m] << endl;
  }
}
