#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007) + (b % 1000000007)) % 1000000007;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007;
}
void Flash() {
  long long n, m;
  cin >> n >> m;
  string second[n];
  for (long long i = 0; i < n; i++) {
    cin >> second[i];
  }
  string t[m];
  for (long long i = 0; i < m; i++) {
    cin >> t[i];
  }
  long long q, year;
  long long sy, ty;
  cin >> q;
  while (q--) {
    cin >> year;
    ty = year % m;
    sy = year % n;
    ty = (ty - 1 + m) % m;
    sy = (sy - 1 + n) % n;
    cout << second[sy] << t[ty] << "\n";
  }
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
