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