n = int(input()) S, T = input().split() A = list(map(int, input().split())) ls = len(S) lt = len(T) m = 200000 ma = [-(1 << 30)] * (m + 1) ma[0] = 0 for i in range(m + 1): if i >= ls: ma[i] = max(ma[i], ma[i - ls] + 1) if i >= lt: ma[i] = max(ma[i], ma[i - lt]) for a in A: sc = ma[a] tc = (a - sc * ls) // lt print(" ".join([S] * sc + [T] * tc))