#include <bits/stdc++.h>
using namespace std;
long long even = 0;
long long curr = 0;
long long mod = 998244353;
long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool dfs(int node, vector<int> adj[], vector<int> &visited, int par) {
  curr++;
  visited[node] = par;
  if (par == 1) even++;
  for (auto child : adj[node]) {
    if (visited[child] == 0) {
      if (!dfs(child, adj, visited, -1 * par)) return false;
    } else if ((visited[node] + visited[child]) != 0)
      return false;
  }
  return true;
}
int rep(vector<int> &v, int a) {
  if (a != v[a]) return rep(v, v[a]);
  return a;
}
void uni(vector<int> &v, vector<int> &size, int a, int b) {
  int ra = rep(v, a);
  int rb = rep(v, b);
  if (ra != rb) {
    if (size[ra] < size[rb]) {
      v[ra] = rb;
      size[rb] += size[ra];
    } else {
      v[rb] = ra;
      size[ra] += size[rb];
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  string s[n], t[m];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int y;
    cin >> y;
    y--;
    cout << s[y % n] << t[y % m] << "\n";
  }
  return 0;
}
