N = int(input()) S, T = input().split() s, t = len(S), len(T) A = list(map(int, input().split())) M = 2 * 10 ** 5 ans = [-1] * (M + 1) for i in range(M + 1): for j in range(t*i, M + 1, s): if ans[j] != -1: break ans[j] = i for a in A: r = ans[a] q = (a - r * t) // s v = [S] * q + [T] * r print(*v)