#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const int MAXN = 3 * 1011;
void solve() {
  int n;
  int m;
  cin >> n >> m;
  vector<string> left;
  vector<string> right;
  int maxq = 2022;
  map<int, string> answr;
  for (int i = 0; i < n; ++i) {
    string crr;
    cin >> crr;
    left.push_back(crr);
  }
  for (int i = 0; i < m; ++i) {
    string crr;
    cin >> crr;
    right.push_back(crr);
  }
  int l_ind = 0;
  int r_ind = 0;
  for (int i = 0; i < maxq; ++i) {
    answr[i] = left[l_ind] + right[r_ind];
    l_ind++;
    l_ind %= n;
    r_ind++;
    r_ind %= m;
  }
  int q;
  cin >> q;
  while (q--) {
    int crr;
    cin >> crr;
    crr--;
    crr %= (n * m);
    cout << answr[crr] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout.precision(20);
  solve();
  return 0;
}
