#include <bits/stdc++.h>
using namespace std;
string a[30], b[30], s[2500];
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  int cnt = 1;
  int i = 1, j = 1;
  while (cnt <= n * m) {
    s[cnt] = a[i] + b[j];
    ++i;
    ++j;
    ++cnt;
    if (i > n) i = 1;
    if (j > m) j = 1;
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    int x;
    scanf("%d", &x);
    if (x > n * m) x %= n * m;
    if (x == 0) x = n * m;
    cout << s[x] << "\n";
  }
  return 0;
}
