#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
string a[22], b[22];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int y1 = x % n;
    int y2 = x % m;
    string ans;
    if (y1 == 0) y1 = n;
    if (y2 == 0) y2 = m;
    ans = ans + a[y1] + b[y2];
    cout << ans << endl;
  }
  return 0;
}
