#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 20;
int N, M, Q;
string str1[MAX_N + 1], str2[MAX_N + 1];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    cin >> str1[i];
  }
  for (int j = 0; j < M; j++) {
    cin >> str2[j];
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int y;
    scanf("%d", &y);
    y--;
    cout << str1[y % N] << str2[y % M] << endl;
  }
  return 0;
}
