#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
string A[25], B[25];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> 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;
  for (int i = 1; i <= q; i++) {
    int a;
    cin >> a;
    a--;
    cout << A[a % n] << B[a % m] << "\n";
  }
  return 0;
}
