N = int(input()) S, T = input().split() A = list(map(int, input().split())) B = [10**9] * len(S) for i in range(len(S)): B[i*len(T)%len(S)] = min(B[i*len(T)%len(S)], i) for a in A: y = B[a%len(S)] x = (a-len(T)*y)//len(S) print(' '.join([S] * x + [T] * y))